How to Use LISTAGG in Snowflake
Last updated July 25, 2026 · By the SaturnSQL team
LISTAGG(col, ', ') concatenates values from a group into one string, with WITHIN GROUP (ORDER BY ...) controlling the order. Add DISTINCT to drop duplicate values before concatenating.
One string per group
SELECT
customer_id,
LISTAGG(status, ', ') WITHIN GROUP (ORDER BY created_at) AS status_history
FROM orders
GROUP BY customer_id;Distinct values only
SELECT
customer_id,
LISTAGG(DISTINCT status, ', ') AS statuses
FROM orders
GROUP BY customer_id;NULL values are skipped, and the result is limited by the maximum VARCHAR size (16 MB). LISTAGG also works as a window function with an OVER clause when you need the string on every row.
Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free