PwC Interview Question

Write a sql query to delete duplicates records where there is no uniquely identified column

Interview Answer

Anonymous

Sep 2, 2025

When you don’t have a unique column (like an ID), you can still delete duplicates by using window functions (ROW_NUMBER) in SQL. Suppose your table is named Employees and has columns: Name | Department | Salary WITH CTE AS ( SELECT *, ROW_NUMBER() OVER ( PARTITION BY Name, Department, Salary -- columns that define duplicates ORDER BY (SELECT NULL) -- no unique column ) AS rn FROM Employees ) DELETE FROM CTE WHERE rn > 1;