groupConcat
Calculates a concatenated string from a group of strings, optionally separated by a delimiter, and optionally limited by a maximum number of elements.
Calculates a concatenated string from a group of strings, optionally separated by a delimiter, and optionally limited by a maximum number of elements.
:::note If delimiter is specified without limit, it must be the first parameter. If both delimiter and limit are specified, delimiter must precede limit.
Also, if different delimiters are specified as parameters and arguments, the delimiter from arguments will be used only. :::
Syntax
groupConcat[(delimiter [, limit])](expression)Parameters
delimiter— A string that will be used to separate concatenated values. This parameter is optional and defaults to an empty string if not specified.Stringlimit— A positive integer specifying the maximum number of elements to concatenate. If more elements are present, excess elements are ignored. This parameter is optional.UInt*
Arguments
expression— The expression or column name that outputs strings to be concatenated.Stringdelimiter— A string that will be used to separate concatenated values. This parameter is optional and defaults to an empty string or delimiter from parameters if not specified.String
Returned value
Returns a string consisting of the concatenated values of the column or expression. If the group has no elements or only null elements, and the function does not specify a handling for only null values, the result is a nullable string with a null value. String
Examples
Basic usage without a delimiter
SELECT groupConcat(Name) FROM Employees;JohnJaneBobUsing comma as a delimiter (parameter syntax)
SELECT groupConcat(', ')(Name) FROM Employees;John, Jane, BobUsing comma as a delimiter (argument syntax)
SELECT groupConcat(Name, ', ') FROM Employees;John, Jane, BobLimiting the number of concatenated elements
SELECT groupConcat(', ', 2)(Name) FROM Employees;John, JaneIntroduced in version 24.8.