mysqldude

GROUP_CONCAT

Version compatibility

StepMySQLMariaDB
5.65.78.08.4910.610.1111.411.8
GROUP_CONCAT(money ORDER BY money DESC) (original)
original post
✓✓✓✓✓✓✓✓✓
GROUP_CONCAT(... SEPARATOR ':') (original)
original post
✓✓✓✓✓✓✓✓✓
Result longer than group_concat_max_len is silently cut (warning 1260)
version check
⚠ 1260⚠ 1260⚠ 1260⚠ 1260⚠ 1260⚠ 1260⚠ 1260⚠ 1260⚠ 1260
JSON_ARRAYAGG alternative (modern)
modern rewrite
✗ 1305✓✓✓✓✓✓✓✓
GROUP_CONCAT(money ORDER BY money DESC) (original) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
GROUP_CONCAT(... SEPARATOR ':') (original) original post
MySQL 5.6✓5.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
Result longer than group_concat_max_len is silently cut (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
JSON_ARRAYAGG alternative (modern) modern rewrite
MySQL 5.6✗ 13055.7✓8.0✓8.4✓9✓
MariaDB 10.6✓10.11✓11.4✓11.8✓
✓works ✓ 1062fails with the error the step demonstrates ⚠works with a warning ≠runs, result differs ✗fails Tested 2026-11-23 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 (3)
  • Result longer than group_concat_max_len is silently cut (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 3 was cut by GROUP_CONCAT()
  • Result longer than group_concat_max_len is silently cut (warning 1260) (MariaDB 11.8): warning 1260: Row 3 was cut by group_concat()
  • JSON_ARRAYAGG alternative (modern) (MySQL 5.6): error 1305: FUNCTION t_3.JSON_LENGTH does not exist

Related errors: 1260

The original article

First published 2011-04-14. The text below is the original; the table above shows how it behaves on current versions.

The GROUP_CONCAT aggregation function returns a non-NULL set of fields within the group. For example, let us imagine that you have a table prize which consists of events and their respective prizes. The table can be seen below:

mysql> select * from prize;
+----------+-------+-------+
| event_id | place | money |
+----------+-------+-------+
|      101 |     1 |   120 |
|      101 |     2 |    60 |
|      101 |     3 |    30 |
|      102 |     1 |    10 |
|      102 |     2 |     5 |
|      102 |     3 |     2 |
|      103 |     1 |   100 |
|      103 |     2 |    60 |
|      103 |     3 |    40 |
|      401 |     1 |  1000 |
+----------+-------+-------+
10 rows in set (0.00 sec)

Now what we want to do is to get the total prize money per event:

mysql> select event_id, sum(money) from prize group by event_id;
+----------+------------+
| event_id | sum(money) |
+----------+------------+
|      101 |        210 |
|      102 |         17 |
|      103 |        200 |
|      401 |       1000 |
+----------+------------+
4 rows in set (0.00 sec)

But what if we want to for reference purposes get a comma separate list of the prize money that make up the total amount. Then we would use the GROUP_CONCAT function as follows:

mysql> select event_id, group_concat(money), sum(money) from prize group by event_id;
+----------+---------------------+------------+
| event_id | group_concat(money) | sum(money) |
+----------+---------------------+------------+
|      101 | 120,60,30           |        210 |
|      102 | 2,5,10              |         17 |
|      103 | 100,60,40           |        200 |
|      401 | 1000                |       1000 |
+----------+---------------------+------------+
4 rows in set (0.00 sec)

Now there are two things we want to do with this set of reference data, the first is we want this ordered with the highest to the lowest values. For event_id 102 this is not the case:

mysql> select event_id, group_concat(money order by money desc), sum(money) from prize group by event_id;
+----------+-----------------------------------------+------------+
| event_id | group_concat(money order by money desc) | sum(money) |
+----------+-----------------------------------------+------------+
|      101 | 120,60,30                               |        210 |
|      102 | 10,5,2                                  |         17 |
|      103 | 100,60,40                               |        200 |
|      401 | 1000                                    |       1000 |
+----------+-----------------------------------------+------------+
4 rows in set (0.00 sec)

Now the next thing we want to look at is the separator we want to change for a ”;”

mysql> select event_id, group_concat(money order by money desc separator ':') as list, sum(money) from prize group by event_id;
+----------+-----------+------------+
| event_id | list      | sum(money) |
+----------+-----------+------------+
|      101 | 120:60:30 |        210 |
|      102 | 10:5:2    |         17 |
|      103 | 100:60:40 |        200 |
|      401 | 1000      |       1000 |
+----------+-----------+------------+
4 rows in set (0.00 sec)