Interview Question

Find duplicate records

GROUP BY the duplicate key and use HAVING COUNT(*) > 1.

💡 Concept ✅ Quick Revision 🗃️ SQL

Answer

Duplicate values can be found by grouping the candidate key columns and keeping groups with more than one row. • GROUP BY defines which values count as duplicates. • COUNT(*) measures each group size. • Include every column that belongs to the duplicate definition.

💡 SQL Example

SELECT email, COUNT(*) AS copies FROM users GROUP BY email HAVING COUNT(*) > 1;

Result

Repeated email values and their counts

⚡ Quick Revision

GROUP BY the duplicate key and use HAVING COUNT(*) > 1.