MySQL GROUP_CONCAT is a very important function. MySQL GROUP_CONCAT is added to MySQL 4.1. the syntax of this function is described in detail below.
MySQL GROUP_CONCAT (expr)
The complete syntax is as follows: GROUP_CONCAT ([DISTINCT] expr [, expr...]
[Order by {unsigned_integer | col_name | formula} [ASC | DESC] [, col...]
[SEPARATOR str_val])
The MySQL GROUP_CONCAT function is added to MySQL 4.1. The function returns a string consisting of values in the group: 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 get the link value of a combination of expressions. You can use DISTINCT to exclude duplicate values. If you want to sort the values in the result,
You can use the order by clause. To sort in reverse ORDER, you can add a DESC (descending) keyword to the column name used for sorting in the order by clause.
. The default value is ascending, which can be explicitly specified by the ASC keyword.
A separator is a string value that is inserted into the result value. The default value is a comma (",").
You can completely remove this SEPARATOR by specifying the SEPARATOR.
In your configuration, use the variable group_concat_max_len to set a maximum length.
Run the following syntax: SET [SESSION | GLOBAL] group_concat_max_len = unsigned_integer;
If the maximum length is set, the result value is cut to this maximum length.
The GROUP_CONCAT () function is an enhanced basic LIST () function supported by Sybase SQL Anywhere.
If there is only one column and no other options are specified, GROUP_CONCAT () is a LIST () function with great limitations on backward compatibility.
LIST () has a default sorting order.
If the characters in the group are too long, you can set system parameters.
SET @ global. group_concat_max_len = 40000;
SQL date functions
Provides you with an in-depth understanding of the MYSQL Cast function.
Learn more about mysql CONCAT () Functions
How to view the three MySQL character sets
How to modify the default Character Set of mysql