GROUP_CONCAT() in MySQL — How It Works
What the MySQL GROUP_CONCAT() function does, with an example.
Published October 21, 2026
GROUP_CONCAT() joins values from a group into one comma-separated string. You can set the order and separator.
How it works
Output is truncated at group_concat_max_len (default 1024).
Try it in MySQL
SELECT GROUP_CONCAT(name) FROM tags WHERE post_id = 1
php,mysql,sql
SELECT GROUP_CONCAT(name ORDER BY name SEPARATOR '; ') FROM tags
a; b; c
SELECT post_id, GROUP_CONCAT(DISTINCT tag) FROM post_tags GROUP BY post_id
tags per post
Practical examples
Example 1
SELECT GROUP_CONCAT(name) FROM tags WHERE post_id = 1;
-- php,mysql,sqlExample 2
SELECT GROUP_CONCAT(name ORDER BY name SEPARATOR '; ') FROM tags;
-- a; b; cExample 3
SELECT post_id, GROUP_CONCAT(DISTINCT tag) FROM post_tags GROUP BY post_id;
-- tags per postUse it in a real query
SELECT GROUP_CONCAT(name) FROM tags WHERE post_id = 1;Common mistakes
- Truncation at 1024 characters.
- Splitting concatenated values later (anti-pattern).
- Forgetting DISTINCT for duplicates.
Key takeaways
- GROUP_CONCAT() in one line: GROUP_CONCAT() joins values from a group into one comma-separated string.
- Try queries in a test database first.
- Check NULL handling and data types.
FAQ
Increase the limit?
SET SESSION group_concat_max_len = 100000;
Does GROUP_CONCAT() work in other databases?
Most have an equivalent, but names and syntax vary between MySQL, PostgreSQL, SQL Server and SQLite.