How to Use GROUP_CONCAT in MySQL
Last updated July 24, 2026 · By the SaturnSQL team
GROUP_CONCAT collapses grouped rows into one delimited string, with optional DISTINCT, ORDER BY, and SEPARATOR. Results are silently truncated at group_concat_max_len (default 1024), so raise it for long lists.
DISTINCT deduplicates before concatenating, and ORDER BY inside the function makes the output stable, which matters if you diff results between runs. The default separator is a comma with no space, so set SEPARATOR explicitly whenever the output is meant to be read by a person.
SELECT customer_id,
GROUP_CONCAT(DISTINCT product_name ORDER BY product_name SEPARATOR ', ') AS products
FROM order_items
GROUP BY customer_id;Raise the length limit for the session
Truncation at group_concat_max_len is silent: no warning in most clients, just a string cut short mid-value. The default is 1024 bytes, which one long list will exceed. Raising it for the session is enough for ad-hoc work; change the server config if application queries depend on it.
SET SESSION group_concat_max_len = 100000;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