Because the GROUP_CONCAT function is an aggregate function, to sort the values, you must use the ORDER BY clause inside the function, not in the ORDER BY in the SELECT statement. The SELECT clause returns one string value so the ORDER BY clause does not take any effect in this statement.
The GROUP_CONCAT() function in MySQL is used to concatenate data from multiple rows into one field. This is an aggregate (GROUP BY) function which returns a String value, if the group contains at least one non-NULL value. Otherwise, it returns NULL.
Sure, see http://dev.mysql.com/doc/refman/...tions.html#function_group-concat:
SELECT student_name,
GROUP_CONCAT(DISTINCT test_score ORDER BY test_score DESC SEPARATOR ' ')
FROM student
GROUP BY student_name;
Do you mean to order by?
SELECT _key,
COUNT(*) as cnt,
GROUP_CONCAT(_value ORDER BY _value SEPARATOR ', ') as value_list
FROM group_concat_test
GROUP BY _key
ORDER BY _key;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With