This article is reproduced from De.cel, "MySQL string connection function CONCAT, Concat_ws,group_concat"
In search of MySQL How to implement a column of multiple rows of data merge into a row, found the group_contact function, which is more convenient than SQL Server in the Select @[email protected]+ column name from the table name, the form of a lot easier , a small summary of the string join function here.
CONCAT (str1, str2,...): Returns the string resulting from the connection parameter. If any one of the arguments is NULL, the return value is null.
Concat_ws (separator,str1,str2,...): CONCAT with separator, is a special form of CONCAT (). The first parameter is the delimiter for the other parameter. The position of the delimiter is placed between the two strings to be concatenated. The delimiter can be a string, or it can be another parameter. If the delimiter is null, the result is null. The function ignores NULL values after any delimiter parameters. e.g:
MySQL > SELECT concat_ws (', ', ' First name ', NULL, ' last name '); -First Name,last Name
Group_concat ([DISTINCT] field to connect [order by Asc/desc sort field] [Separator ' delimiter ']): Can be used to row to column. e.g: 
mysql> select * from TB;
+------+------+ 
| id | name | &NBSP,
+------+------+ 
| 1 |-| &NBSP
| 1 | | &NBSP
| 1 | | &NBSP
| 2 | | &NBSP
| 3 | |
| 3 | | &NBSP
+------+------+ 
myql> Select Id,group_concat (name) from the TB group by ID;
+------+--------------------+ 
| id | group_concat (name) |
+------+--------------------+ | 1 | 10,20,20 | &NBSP
| 2 | |
| 3 | 200,500 | &NBSP
+------+--------------------+ 
Mysql> Select id< Span style= "color: #ff0000; Font-size:large; " >,group_concat (name separator '; ') from TB Group by ID;
+------+----------------------------------+&NBSP;
| id | group_concat ( Name separator '; ') &NBSP;
| +------+----------------------------------+&NBSP;
| 1 | 10;20;20 | &NBSP
| 2 | |
| 3 | 200;500 | &NBSP
+------+----------------------------------+&NBSP;
MySQL > select Id,group_concat (distinct name) from TB Group by ID;
+------+-----------------------------+
| ID | Group_concat (distinct name) |
+------+-----------------------------+
| 1 | 10,20 |
| 2 | 20 |
| 3 | 200,500 |
+------+-----------------------------+
MySQL string connection function CONCAT, concat_ws,group_contact