3

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

11111  [email protected]
22222  [email protected]  
33333  [email protected]
44444  [email protected]

To this

[email protected]  11111, 22222, 33333, 44444

Thanks!

1

2 Answers 2

7

group_concat to the rescue:

SELECT   email, GROUP_CONCAT(other ORDER BY other ASC SEPARATOR ', ') 
FROM     mytable
GROUP BY email
Sign up to request clarification or add additional context in comments.

Comments

1

I found it

select email,GROUP_CONCAT(tel1,',',tel2) as phones from table group by email;

Thanks!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.