Outdated Version

You are viewing an older version of this section. View current production version.

GROUP_CONCAT

Aggregate function. Concatenates all of the values passed in during aggregation.

Info

This aggregate function is not to be confused with CONCAT, which is a non-aggregate function returning a concatenation of its list of arguments.

GROUP_CONCAT( [DISTINCT]
           expression, [ expression, [expression ...]]
           [SEPARATOR string] )

Arguments

  • DISTINCT: optionally filter the result set for only unique sets of expressions
  • expression: any set of expressions. This may be a column name, the result of another function, or a math operation.
  • SEPARATOR string: by default, the separator character is the comma “,". This argument overrides the default.

Return Type

The concatenated string.

Examples

memsql> select group_concat(ship_code) from products;
+-------------------------+
| group_concat(ship_code) |
+-------------------------+
| A,B,A,A,C,D,A,B         |
+-------------------------+

memsql> select group_concat(DISTINCT ship_code) as distinct_codes from products;
+----------------+
| distinct_codes |
+----------------+
| A,B,C,D        |
+----------------+

memsql> select group_concat(DISTINCT ship_code SEPARATOR " ")
-> as distinct_codes from products;
+----------------+
| distinct_codes |
+----------------+
| A B C D        |
+----------------+

memsql> select group_concat(first_name, " ", last_name) from BFFs;
+------------------------------------------+
| group_concat(first_name, " ", last_name) |
+------------------------------------------+
| Cecelia Cruz,Ari Floo,Skylar Rhodes      |
+------------------------------------------+