TransWikia.com

How to merge same Ids data with mysql?

Stack Overflow Asked on January 3, 2022

I have records like this after applying joins

id   name   item
1    bil    Books
2    mike   Table
2    mike   chair
3    josh   pen
3    josh   pencil
4    peter  copy

But, I want them to look like this

id   name   item
1    bil    Books
2    mike   Table,chair
3    josh   pen, pencil
4    peter  copy 

How to achieve this?

One Answer

Use group by and group_concat():

select id, name, group_concat(item) items
from mytable
group by id, name

Answered by GMB on January 3, 2022

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP