SET SESSION group_concat_max_len = 2; select type, group_concat(distinct id) from test GROUP BY type DESC;