SQLite 3 reference · Aggregate Functions

SQLite GROUP_CONCAT() Function

Join a group's non-NULL values into one string, separated by commas or a separator you give.

SQLite 3

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

group_concat(X, SEP ORDER BY ...)

Parameters

ParameterDescription
X A column or expression.
SEP optional The separator. Default: ','
ORDER BY optional The order to join values in (3.44+).

Return value

Text, or NULL for no values.

Examples

One row per countryTry it yourself
SELECT country, group_concat(name, '; ') AS customers
FROM customers
GROUP BY country
HAVING count(*) > 1;

Output

country | customers
UK | Ada Lovelace; Alan Turing
USA | Grace Hopper; Linus Torvalds; Margaret Hamilton; Barbara Liskov; Katherine Johnson
In a fixed orderTry it yourself
SELECT group_concat(name, ', ' ORDER BY name) AS categories
FROM categories;

Output

categories
Books, Electronics, Home, Toys

Version history

VersionChange
SQLite 3.44.0An ORDER BY clause inside the call sets the order of the joined values.

In other languages

Was this page helpful?