I have three table and want to join them but the join returns a single row multiple time when using group by parent id from contact table.
contact table-
| id | Name |
|---|---|
| 1 | Murad |
| 2 | Tajharul |
phone table-
| id | contact_id | phone |
|---|---|---|
| 1 | 1 | 017 |
| 2 | 2 | 014 |
| 3 | 2 | 015 |
email table-
| id | contact_id | |
|---|---|---|
| 1 | 1 | mur@test.com |
| 2 | 1 | has@test.com |
| 3 | 1 | tan@test.com |
| 4 | 2 | taj@test.com |
| 5 | 2 | har@test.com |
Desired Output-
| id | Name | Phone | |
|---|---|---|---|
| 1 | Murad | 017 | mur@test.com,has@test.com,tan@test.com |
| 2 | Tajharul | 014,015 | taj@test.com,har@test.com |
Here is what I have tried so far-
SELECT contact.name , GROUP_CONCAT(phone.phone) phone, GROUP_CONCAT(email.email) email
FROM
contact
JOIN phone ON contact.id = phone.contact_id
JOIN email ON contact.id = email.contact_id
GROUP BY contact.id
MySQL Fiddle link: http://sqlfiddle.com/#!9/ded29f/1