MySQL get comma separated values in result

Get id or field value in comma separate string. Use GROUP_CONCAT for getting result in comma separate string. Function useful when you want to use id or field value in comma separate or with other character separate string.

About GROUP_CONCAT:
This function returns a string result with the concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values.

Syntax:

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

Simple example query:

SELECT student_name,
GROUP_CONCAT(DISTINCT test_score
    ORDER BY test_score
    DESC
    SEPARATOR ',') AS result_score
FROM student
GROUP BY student_name;