Forum

write sql query to ...
 
Share:
Notifications
Clear all

write sql query to find duplicate rows in a database


jeevan 123
Posts: 18
Topic starter
(@jeevan303500)
Active Member
Joined: 12 months ago

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

Leave a reply

Author Name

Author Email

Title *

 
Preview 0 Revisions Saved
Share: