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
Syntax
group_concat(X, SEP ORDER BY ...)
Parameters
| Parameter | Description |
|---|---|
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
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
SELECT group_concat(name, ', ' ORDER BY name) AS categories
FROM categories;
Output
categories Books, Electronics, Home, Toys
Version history
| Version | Change |
|---|---|
| SQLite 3.44.0 | An ORDER BY clause inside the call sets the order of the joined values. |
In other languages
STRING_AGG()· PostgreSQL
Related
STRING_AGG()· Join a group's values with a separator, the standard name also used by PostgreSQL and SQL Server.JSON_GROUP_ARRAY()· Aggregate the values of a group into one JSON array, one element per row. SQL NULLs become JSON null.CONCAT_WS()· Join values with a separator between them, skipping NULLs. The ws stands for with separator.- SQL Aggregate Functions · tutorial
- SQL GROUP BY · tutorial