SQLite 3 reference · Aggregate Functions

SQLite STRING_AGG() Function

Join a group's values with a separator, the standard name also used by PostgreSQL and SQL Server.

SQLite 3 Since 3.44.0

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

Syntax

string_agg(X, SEP ORDER BY ...)

Parameters

ParameterDescription
X A column or expression.
SEP The separator (required).
ORDER BY optional The order of the values.

Return value

Text, or NULL for no values.

Examples

Join per groupTry it yourself
SELECT department, string_agg(name, ', ' ORDER BY salary DESC) AS by_salary
FROM employees
GROUP BY department;

Output

department | by_salary
Engineering | Omar Haddad, Mei Chen, Jonas Berg, Priya Nair, Lucas Martin
Management | Sofia Reyes
Sales | Hannah Okafor, Diego Silva, Emma Novak
Support | Ravi Kumar
Unique values, via a subqueryTry it yourself
SELECT string_agg(country, '/') AS countries
FROM (SELECT DISTINCT country FROM customers ORDER BY country);

Output

countries
Japan/Netherlands/Switzerland/UK/USA

Version history

VersionChange
SQLite 3.44.0Added

In other languages

Was this page helpful?