Product Solutions Support
Try MemSQL

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.

Syntax

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

Arguments

Return Type

The return type is a string. The result is made up of the concatenated non-NULL values from the given group, or NULL if there are no non-NULL values.

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      |
+------------------------------------------+
Was this article useful?