Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MySQL – Group by one value and concat other values in one column

I have a database with email and phone columns. One email can have several phones, which results in multiple rows with same email but different phone numbers.

I want to query all emails with it’s phones grouped in one single column.

Example

Convert from this

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

11111  mail@mail.com
22222  mail@mail.com  
33333  mail@mail.com
44444  mail@mail.com

To this

mail@mail.com  11111, 22222, 33333, 44444

Thanks!

>Solution :

group_concat to the rescue:

SELECT   email, GROUP_CONCAT(other ORDER BY other ASC SEPARATOR ', ') 
FROM     mytable
GROUP BY email
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading