HomeInterview QuestionsWrite a SQL query to find duplicate records.

Write a SQL query to find duplicate records.

🟢 Easy Coding Junior level
1Times asked
Jul 2026Last seen
Jul 2026First seen

💡 Model Answer

To locate duplicate rows you group by the columns that define uniqueness and keep only groups that appear more than once. A simple example:

SELECT column1, column2, COUNT(*) AS dup_count

FROM my_table

GROUP BY column1, column2

HAVING COUNT(*) > 1;

Replace column1, column2 with the fields that should be unique (e.g., email, username). The HAVING clause filters groups where the count exceeds one, indicating duplicates. If you want the full duplicate rows, you can join this result back to the original table:

WITH dup AS (

SELECT column1, column2

FROM my_table

GROUP BY column1, column2

HAVING COUNT(*) > 1

)

SELECT t.*

FROM my_table t

JOIN dup USING (column1, column2);

This returns every row that has a duplicate counterpart.

This answer was generated by AI for study purposes. Use it as a starting point — personalize it with your own experience.

🎤 Get questions like this answered in real-time

Assisting AI listens to your interview, captures questions live, and gives you instant AI-powered answers on a discreet on-screen overlay.

Get Assisting AI — Starts at ₹500