Write a SQL query to find duplicate records in a table
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 filters out those appearing only once, leaving only the duplicates for review.
Common Mistakes to Avoid
- Using WHERE instead of HAVING
- Forgetting to group correctly
- Not specifying columns to check
Practice This Question with AI
Answer this question orally or via text and get instant AI-powered feedback on your response quality, structure, and delivery.
Related Interview Questions
What is the difference between LIKE and equals operators in SQL?
Easy
TCSWhat is the difference between DELETE and TRUNCATE commands in SQL?
Easy
FlipkartWhat is ER model in the DBMS?
Medium
FlipkartWhat is database normalization and why is it important?
Medium
FlipkartWhat is the difference between authentication and authorization?
Easy
FlipkartHow do you prioritize tasks when multiple deadlines are approaching?
Medium
Flipkart