Reputation: 609
I have a MySQL table that looks like this:
ID Email
1 [email protected]
1 [email protected]
1 [email protected]
2 [email protected]
2 [email protected]
I would like to merge by ID but keep the "Email" data in the same cell:
ID Email
1 [email protected], [email protected], [email protected]
2 [email protected], [email protected]
How would you advise me to do that?
Upvotes: 0
Views: 28
Reputation: 9583
try
"INSERT INTO NEW_TABLE (ID, EMAIL)
SELECT ID, GROUP_CONCAT(EMAIL)AS EMAIL
FROM OLD_TABLE
GROUP BY ID"
Upvotes: 1