Write a SQL query to find duplicate records in a table
Direct Answer
A SQL question requiring the candidate to demonstrate proficiency in grouping and filtering data.
Why Interviewers Ask This
Data manipulation is crucial for analyzing business metrics. This question checks basic SQL syntax knowledge, specifically the use of GROUP BY and HAVING clauses to identify anomalies or duplicates in datasets.
How to Answer This Question
State the assumption about which column(s) define uniqueness. Write the query using GROUP BY on those columns and HAVING COUNT(*) > 1. Explain the logic step-by-step: grouping rows, counting occurrences, and filtering for counts greater than one.
Key Points to Cover
- Use GROUP BY clause
- Apply HAVING filter
- Count occurrences
Sample Answer
To find duplicates, I would group the records by the unique identifier columns and count them. The query would look like: SELECT email, COUNT(*) FROM users GROUP BY email HAVING COUNT(*) > 1. This groups all emails and f…
Common Mistakes to Avoid
- Using WHERE instead of HAVING
- Forgetting to group correctly
- Not specifying columns to check
Sound confident on this question in 5 minutes
Answer once and get a 30-second AI critique of your structure, content, and delivery. First attempt is free — no signup needed.