Skip to content
>_sqlbuddy

SQL Topic

Duplicate Handling

Duplicate questions test your grasp of DISTINCT, GROUP BY + HAVING COUNT(*) > 1, and ROW_NUMBER for deleting or keeping one row per group.

When is Duplicate Handling used?

Finding duplicate emails or records, de-duplicating before analysis, keeping the latest row per entity.

Core syntax

SELECT email FROM person GROUP BY email HAVING COUNT(*) > 1 — or ROW_NUMBER() OVER (PARTITION BY ...) to keep one row per group.

Common mistakes

  • Forgetting that DISTINCT applies to the whole row, not one column.
  • Treating NULLs as duplicates (they are distinct from each other).
  • Counting without understanding whether duplicates are exact or key-based.

Practice Duplicate Handling questions

Work through them in order — each question builds on the last.

Related topics

Interview preparation