user1029296
user1029296

Reputation: 609

Merge MySQL Duplicates and Keeping Content

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

Answers (1)

andrew
andrew

Reputation: 9583

try

  "INSERT INTO NEW_TABLE (ID, EMAIL) 
      SELECT ID, GROUP_CONCAT(EMAIL)AS EMAIL 
      FROM OLD_TABLE 
      GROUP BY ID"

Upvotes: 1

Related Questions