sorting - MySQL: Sort GROUP_CONCAT values

ID : 20096

viewed : 23

Tags : mysqlsortingsql-order-bygroup-concatmysql

Top 5 Answer for sorting - MySQL: Sort GROUP_CONCAT values

vote vote

100

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; 
vote vote

89

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; 
vote vote

73

vote vote

70

Another way to do the same thing (also requires sorted input):

join -v 1 fileA fileB 

In Bash, if the files are not pre-sorted:

join -v 1 <(sort fileA) <(sort fileB) 
vote vote

60

You can do this unless your files are sorted

diff file-a file-b --new-line-format="" --old-line-format="%L" --unchanged-line-format="" > file-a 

--new-line-format is for lines that are in file b but not in a --old-.. is for lines that are in file a but not in b --unchanged-.. is for lines that are in both. %L makes it so the line is printed exactly.

man diff 

for more details

Top 3 video Explaining sorting - MySQL: Sort GROUP_CONCAT values

Related QUESTION?