May 03, 2022 6:21 am
Here is the SQL query to find duplicate rows in a database.
Using common table expressions we can easily achieve this.
Example data scenario.
Input
ID name salary
1 ABC 1000
2 ABC 1000
3 BCD 2000
Output
ID name salary
1 ABC 1000
2 BCD 2000
SQL Query
With EmpCTE as ( Select *, Rownumber() Over(Partition By ID order By ID) As Rownumber From Emp ) Delete from EmpCTE where Rownumber>1