mysqldude

GROUP_CONCAT unique values

Version compatibility

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
GROUP_CONCAT(col1) (original)
original post
✓✓✓✓✓✓✓✓✓
GROUP_CONCAT(DISTINCT col1) (original)
original post
✓✓✓✓✓✓✓✓✓
GROUP_CONCAT is cut at group_concat_max_len (default 1024) with warning 1260
version check
⚠ 1260⚠ 1260⚠ 1260⚠ 1260⚠ 1260⚠ 1260⚠ 1260⚠ 1260⚠ 1260
GROUP_CONCAT(col1) (original) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
GROUP_CONCAT(DISTINCT col1) (original) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
GROUP_CONCAT is cut at group_concat_max_len (default 1024) with warning 1260 version check
MySQL 5.6⚠ 12605.7⚠ 12608.0⚠ 12608.4⚠ 12609⚠ 1260
MariaDB 10.6⚠ 126010.11⚠ 126011.4⚠ 126011.8⚠ 1260
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-25 on 5.6.51, 5.7.44, 8.0.46, 8.4.13, 9.7.4, 10.6.28, 10.11.19, 11.4.13, 11.8.9
What the warnings and failures say (2)
  • GROUP_CONCAT is cut at group_concat_max_len (default 1024) with warning 1260 (MySQL 5.6, MySQL 5.7, MySQL 8.0, MySQL 8.4, MySQL 9, MariaDB 10.6, MariaDB 10.11, MariaDB 11.4): warning 1260: Row 4 was cut by GROUP_CONCAT()
  • GROUP_CONCAT is cut at group_concat_max_len (default 1024) with warning 1260 (MariaDB 11.8): warning 1260: Row 4 was cut by group_concat()

The original article

First published 2012-05-08. The text below is the original; the table above shows how it behaves on current versions.

GROUP_CONCAT allows you to return a list of values in a single field. Consider the following table:

mysql> select * from t1;
+--------+------+------+
| col1   | col2 | col3 |
+--------+------+------+
| ronan4 |  100 |  115 |
| ronan4 |  155 |  116 |
| ronan4 |  225 |  250 |
| ronan4 |  300 |  275 |
| ronan4 |  325 |  350 |
| ronan4 |    1 |    2 |
| ronan4 |    1 |    3 |
| t13    |    7 |    6 |
+--------+------+------+
8 rows in set (0.00 sec)

Here we want to return a list of the users in col1.

mysql> select group_concat(col1) from t1;
+------------------------------------------------------+
| group_concat(col1)                                   |
+------------------------------------------------------+
| ronan4,ronan4,ronan4,ronan4,ronan4,ronan4,ronan4,t13 |
+------------------------------------------------------+
1 row in set (0.00 sec)

So far so good but what if we want to remove the duplicate values in this list. In this case here we need to specify a DISTINCT inside the GROUP_CONCAT function.

mysql> select group_concat(distinct col1) from t1;
+-----------------------------+
| group_concat(distinct col1) |
+-----------------------------+
| ronan4,t13                  |
+-----------------------------+
1 row in set (0.00 sec)