Krush23
Krush23

Reputation: 741

List of duplicate values SQL

Duplicate values can be found using this

SELECT email, COUNT(email) 
FROM users
GROUP BY email
HAVING COUNT(email) > 1

for the data

ID   NAME   EMAIL
1    John   [email protected]
2    Sam    [email protected]
3    Tom    [email protected]
4    Bob    [email protected]
5    mob    [email protected]

But the table I need is

NAME             EMAIL
John, Sam, Tom   [email protected]
Bob, mob         [email protected]

Upvotes: 2

Views: 39

Answers (1)

Joel Coehoorn
Joel Coehoorn

Reputation: 415630

You need the GROUP_CONCAT() function, which IIRC works in both MySql and Sqlite, but handles NULL values different between the two (I may be wrong on that last part).

SELECT group_concat(name) as Name, email
FROM users
GROUP BY email
HAVING COUNT(email) > 1

Upvotes: 3

Related Questions