When a single ID corresponds to multiple names using the function group_concat (), the name is merged into one row for multiple rows of data.
Complete Syntax:
GROUP_CONCAT (expr)
This function returns a string with a non-NULL value from a group of connections. The complete syntax is as follows:
GROUP_CONCAT ([DISTINCT] expr [, expr...]
[Order by {unsigned_integer | col_name | expr}
[ASC | DESC] [, col_name...]
[SEPARATOR str_val])
Mysql> SELECT student_name,
-> GROUP_CONCAT (test_score)
-> FROM student
-> Group by student_name;
Or:
Mysql> SELECT student_name,
-> GROUP_CONCAT (DISTINCT test_score
-> Order by test_score desc separator '')
-> FROM student
-> Group by student_name;
In MySQL, you can obtain the join value of expression combinations. You can use DISTINCT to delete duplicate values. If you want to sort multiple result values, use the order by clause. To sort in reverse ORDER, add the DESC (descending) keyword to the column name that you want to sort using the order by clause. The default order is ascending. You can use ASC to specify it. SEPARATOR follows the string value in the middle of the value of the inserted result. The default value is comma (','). You can delete all separators by specifying the SEPARATOR.
Using group_concat_max_len system variables, you can set the maximum allowed length. The syntax for this operation in the program is as follows, where val is an unsigned integer:
SET [SESSION | GLOBAL] group_concat_max_len = val;