Home › Interview Questions › Write a SQL query to find duplicate records in the…

Write a SQL query to find duplicate records in the employee table.

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

💡 Model Answer

To find duplicate records in the employee table, group by all columns and filter groups with count > 1. Example:

SELECT emp_id, first_name, last_name, hire_date, COUNT(*) AS dup_cnt

FROM employee

GROUP BY emp_id, first_name, last_name, hire_date

HAVING COUNT(*) > 1;

This returns the rows that appear more than once. If you want to see the duplicate rows themselves, you can join this result back to the original table. Complexity is O(n) with hashing or O(n log n) with sorting, depending on the DB engine. Ensure you have appropriate indexes on the columns used in the GROUP BY to improve performance.

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