The group_concat function and connection field in MySQL. The complete syntax of the group_concat function in MySQL is as follows: group_concat ([DISTINCT] field to be connected [Order by asc/DESC sorting field] [Separator 'delimiter']) basic query mysql> select * from aa; + ------ + | id | name | + ------ + | 1 | 10 | 1 | 20 | 1 | 20 | 2 | 20 | 3 | 200 | | 3 | 500 | + ------ + 6 rows in set (0.00 sec) group by id, print the value of the name field in one row, and separate them by commas (,) (default) mysql> select id, group_concat (name) from aa group by id; + ------ + -------------------- + | id | group_concat (name) | + ------ + -------------------- + | 1 | 10, 20, 20 | 2 | 20 | 3 | 200,500 | + ------ + ------------------ + 3 rows in set (0.00 sec) grouped by id, print the value of the name field in one row, use semicolons to separate mysql> select id, group_concat (name separator ';') from aa group by id; + ------ + ---------------------------------- + | id | group_concat (name separator ';') | + ------ + ------------------------------ + | 1 | 10; 20; 20 | 2 | 20 | 3 | 200; 500 | + ------ + ------------------------------------ + 3 rows in set (0.00 sec) group by id and print the value of the redundant name field in one row. Separate them by commas (,) from mysql> select id, group_concat (distinct name) from aa group by id; + ------ + ----------------------------- + | id | group_concat (distinct name) | + ------ + --------------------------- + | 1 | 200,500 | 2 | 20 | 3 | 0.00 | + ------ + --------------------------- + 3 rows in set (sec) grouped by id, print the value of the name field in one row, separated by commas (,), in reverse order of name mysql> select id, group_concat (name order by name desc) from aa group by id; + ------ + ------------------------------------- + | id | group_concat (name order by name desc) | + ------ + --------------------------------------- + | 1 |, 10 | 2 | 20 | 3 | 500,200 | + ------ + --------------------------------------- + 3 rows in set (0.00 sec)