Write a SQL query to find duplicate records in a table

SQL
Easy
Flipkart
61.4K views

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.

Start Practicing

Related Interview Questions

Browse all 19 SQL questionsBrowse all 52 Flipkart questions