Finding Duplicates
Duplicates sneak into every real database: the same email twice, the same order imported twice. GROUP BY plus HAVING finds them.
Group by the value that should be unique, then keep the groups with more than one row:
Martinez shows up twice: Robert and Nicole.
Group by several columns to check a combination:
To see the full rows behind a duplicate, feed the result into IN:
Check your understanding
Which query lists the last names used by more than one employee?
Examples run on the employees sample database. Open any of them in the playground to experiment.