How to Use STRING_AGG in BigQuery

Last updated July 26, 2026 · By the SaturnSQL team

STRING_AGG(column, separator) combines grouped row values into a single delimited string. Add ORDER BY inside the call to control value order.

SELECT order_id, STRING_AGG(product_name, ', ') AS products
FROM order_items
GROUP BY order_id;

Ordered and deduplicated

SELECT customer_id,
       STRING_AGG(DISTINCT product_name, ', ' ORDER BY product_name) AS distinct_products
FROM order_items
GROUP BY customer_id;

STRING_AGG ignores NULL values automatically, so you do not need a WHERE clause to filter them out first.

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

Related BigQuery guides