This query finds duplicate email addresses in a clients table:
SELECT email, count(*), group_concat(name, ',') AS names
FROM clients
GROUP BY email
HAVING count(*) > 1
Let's go through that query one step at a time:
id | name | |
1 | mr darcy | darcy@pemberley.com |
2 | luna | luna@mice.com |
3 | nala | me@cartoon.com |
4 | tigger | me@cartoon.com |
id | name | |
1 | mr darcy | darcy@pemberley.com |
id | name | |
2 | luna | luna@mice.com |
id | name | |
3 | nala | me@cartoon.com |
4 | tigger | me@cartoon.com |
count(*) | names | |
darcy@pemberley.com | 1 | mr darcy |
luna@mice.com | 1 | luna |
me@cartoon.com | 2 | nala,tigger |
count(*) | names | |
me@cartoon.com | 2 | nala,tigger |