Reputation: 9
just think I have a table like shown below
**id** **product**
2 chocolate
1 chocolate
2 pepsi
3 fanta
2 pepsi
4 chocolate
5 chips
3 pizza
1 coke
2 chips
6 burger
7 sprite
0 pepsi
and want to arrange the above table in the manner shown below using only mysql
**id** **product**
0 pepsi
1 chocolate, coke
2 chocolate,fanta,chips
3 fanta,pizza
4 chocolate
5 chips
6 burger
7 sprite
how do I do it?
Upvotes: 0
Views: 510
Reputation: 204766
select id, group_concat(distinct product) as products
from your_table
group by id
order by id
Upvotes: 1