Find duplicate emails with HAVING

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:

1 FROM clients

id name email
1 mr darcy darcy@pemberley.com
2 luna luna@mice.com
3 nala me@cartoon.com
4 tigger me@cartoon.com

2 GROUP BY email

id name email
1 mr darcy darcy@pemberley.com
id name email
2 luna luna@mice.com
id name email
3 nala me@cartoon.com
4 tigger me@cartoon.com

3 SELECT email, count(*), group_concat(name, ',') AS names

email count(*) names
darcy@pemberley.com 1 mr darcy
luna@mice.com 1 luna
me@cartoon.com 2 nala,tigger

4 HAVING count(*) > 1

email count(*) names
me@cartoon.com 2 nala,tigger