Skip to main content

GROUP_CONCAT

Description​

The GROUP_CONCAT function concatenates multiple rows of results in the result set into a string.

Syntax​

GROUP_CONCAT([DISTINCT] <str>[, <sep>] [ORDER BY { <col_name> | <expr>} [ASC | DESC]])

Parameters​

ParametersDescription
<str>Required. The expression of the value to be concatenated.
<sep>Optional. The separator between strings.
<col_name>Optional. The column used for sorting.
<expr>Optional. The expression used for sorting.

Return Value​

Returns a value of type VARCHAR.

Example​

select value from test;
+-------+
| value |
+-------+
| a |
| b |
| c |
| c |
+-------+
select GROUP_CONCAT(value) from test;
+-----------------------+
| GROUP_CONCAT(`value`) |
+-----------------------+
| a, b, c, c |
+-----------------------+
select GROUP_CONCAT(DISTINCT value) from test;
+-----------------------+
| GROUP_CONCAT(`value`) |
+-----------------------+
| a, b, c |
+-----------------------+
select GROUP_CONCAT(value, " ") from test;
+----------------------------+
| GROUP_CONCAT(`value`, ' ') |
+----------------------------+
| a b c c |
+----------------------------+
select GROUP_CONCAT(value, NULL) from test;
+----------------------------+
| GROUP_CONCAT(`value`, NULL)|
+----------------------------+
| NULL |
+----------------------------+