Category Archives: MySQL

MySQL GROUP_CONCAT

MySQL cames with lot of aggregate functions. They process data from individual rows while GROUP BY is executing. Here is one example of GROUP_CONCAT:

mysql> SELECT   user_id,
         GROUP_CONCAT(id) _id,
         COUNT(1)
FROM     bets
WHERE    user_id = 99
GROUP BY user_id;
+---------+-----------------------------------------+----------+
| user_id | _id                                     | COUNT(1) |
+---------+-----------------------------------------+----------+
|      99 | 2857,2856,2858,2851,2852,2855,2853,2854 |       12 |
+---------+-----------------------------------------+----------+