mysql multiple group_concat order preservation
group-by, group-concat, mysql, sql
Solution
You can use an `ORDER BY` clause inside the `GROUP_CONCAT` function:
SELECT a,
GROUP_CONCAT(b ORDER BY b),
GROUP_CONCAT(c ORDER BY c)
FROM mytable GROUP BY a
Problem
let's say I have a table mytable: `select * from mytable`: ` +------+------+------+ | a | b | c | +------+------+------+ | 1 | 1 | a | | 1 | 2 | b | +------+------+------+ ` I want to group both the columns b and c with `group_concat` function: `select a, group_concat(b), group_concat(c) from mytable group by a` ` +------+-----------------+-----------------+ | a | group_concat(b) | group_concat(c) | +------+-----------------+-----------------+ | 1 | 1,2 | a,b | +------+-----------------+-----------------+ ` My question is, do the mysql guarantee, that the `group_concat` will be always in the same order, that I won't get results like 1, 2 in the second column and b, a in the third column?