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!

Related Questions

form validation with data ranges

2  Asked on August 7, 2020 by eniol


How to format this output?

2  Asked on August 6, 2020 by shantanu-jain


uploading csv file django using a form

2  Asked on August 5, 2020 by sheraram_prajapat


Set focus to another Control

3  Asked on August 4, 2020 by binu


Animate gradient bar chart – matplotlib

1  Asked on August 4, 2020 by jonboy


c# error – Can not convert Array to byte array

1  Asked on August 2, 2020 by rakesh


Correcting Business name misspellings

1  Asked on August 2, 2020 by jonathan-rauscher


How to cut a string to the first “/” from right to left c# .net

1  Asked on August 1, 2020 by ignacio-gomez


Inserting random data from a list

2  Asked on August 1, 2020 by smiley


Invalid token SELECT

2  Asked on July 31, 2020 by virendra-varma


Django – No column found for custom field?

0  Asked on July 29, 2020 by jare42


Ask a Question

Get help from others!

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