Configure HTML/JavaScript

Thursday, February 10, 2011

Getting row values in comma separated using GROUP by or other queries in MySQL

Hi,

Some time we need to see some string type data of different rows in comma separated or other separated in a single field. for this type of implementation mysql have a function GROUP_CONCAT(field_value) . we can add GROUP BY cluse to get comma separated values in different cases.

Example:

GROUP_CONCAT([DISTINCT] expr [,expr ...]
[ORDER BY {unsigned_integer | col_name | expr}
[ASC | DESC] [,col_name ...]]
[SEPARATOR str_val])

mysql> SELECT student_name,
-> GROUP_CONCAT(test_score)
-> FROM student
-> GROUP BY student_name;

in reference to: Aniruddh (view on Google Sidewiki)

No comments:

Post a Comment