views:

38

answers:

2

I have a single MYSQL Question and need help ASAP. Database:

-------------------------------------------------------------------
Email                 | Name                      | Tag
-------------------------------------------------------------------
[email protected]         |Test Person               | TagOne
[email protected]         |Test Person               | Tag Two
-------------------------------------------------------------------

Need an SQL query that will return

-------------------------------------------------------------------
Email                 | Name                      | Tag
-------------------------------------------------------------------
[email protected]         |Test Person               | TagOne, Tag Two
-------------------------------------------------------------------

Any help?

+2  A: 

Use:

  SELECT t.email,
         t.name,
         GROUP_CONCAT(DISTINCT t.tag ORDER BY t.tag SEPARATOR ', ')
    FROM YOUR_TABLE t
GROUP BY t.email, t.name

Reference:

OMG Ponies
Wow! Only just saw your post as got confused thinking it was mine. We posted at the same time! What a great forum. Will be back. thank you for your help!
Jono
A: 

For anyone else trying to do this and is stuck spending hours for a solution:

SELECT Email, Name, GROUP_CONCAT(Tag ORDER BY Tag ASC SEPARATOR ', ') FROM Table GROUP BY Email

Jono
OMG Ponies