We have a mysql table
id name groupid
1 user1 0
2 user2 0
3 user3 1
4 user4 1
We want the GROUP CONCAT such that we get the output as
1,user1;2,user2---3,user3;4,user4
This does what you describe:
create table NoOneEverNamesTheTableInSqlQuestions (
id int,
name text,
groupid int
);
insert into NoOneEverNamesTheTableInSqlQuestions values
(1, 'user1', 0),
(2, 'user2', 0),
(3, 'user3', 1),
(4, 'user4', 1);
select group_concat(g separator '---') as output
from (
select group_concat(concat_ws(',',id,name) separator ';') as g
from NoOneEverNamesTheTableInSqlQuestions
group by groupid
) as g;
Output, tested with MySQL 8.0.0-dmr:
+-----------------------------------+
| output |
+-----------------------------------+
| 1,user1;2,user2---3,user3;4,user4 |
+-----------------------------------+
But I don't know why you would want to do this. It seems like something that would be easier to do in application code.