Skip to interview prep
Apexed

4. How do you find duplicate rows in a table?

EasySQL

Technical
Show model answer

Group by the columns that define a duplicate and keep groups with more than one row: `SELECT email, COUNT(*) FROM users GROUP BY email HAVING COUNT(*) > 1;`

To remove extras, number rows with ROW_NUMBER() OVER (PARTITION BY email ORDER BY created_at) and delete those with a number above 1.

How do you find duplicate rows in a table — Data & analytics interview question — Apexed