Suppose we have the situation to delete some duplicate records in our table. Suppose consider one table
create table #Test
(
EmpID int,
EmpName varchar(50)
)
–Insert the Records into #Test table
insert into #Test values(1,’Daya‘)
insert into #Test values(1,’Daya‘)
insert into #Test values(1,’Daya‘)
Now i have two duplicate records inserted and i want to delete those records. The following query will delete the duplicate records
–Query to Delete Duplicate Records
WITH Emp AS (SELECT ROW_NUMBER ( ) OVER ( PARTITION BY EmpID, EmpName ORDER BY EmpID ) AS RNUM FROM #Test )
DELETE FROM Emp WHERE RNUM > 1
Advertisement
If the records,then this query will help us.
if there two different records having duplicates.Then, how to remove the duplicates of these two records.
Please provide one example as what exactly you want
thanks your answer is right
but that is so complex
good luck
Good One
Thanks!!!!!!!!
the query working well but need to understand i appreciate if could you explain about given query to delete the duplicate records.
Thank you
WITH Emp AS (SELECT ROW_NUMBER ( ) OVER ( PARTITION BY EmpID, EmpName ORDER BY EmpID ) AS RNUM FROM #Test )
DELETE FROM Emp WHERE RNUM > 1
can u explain it in detail.
i couldn’t undrestand
Thanks
good one…
I find two other method to solve the issue.
Delete Duplicate records in SQL Server
very nice post.your solution solve my problem.
The solution is good one,it is helpful
That was very helpful my friend. Thank you so much.
Hi,
It is working fine.But i couldn’t understand . any simple method.
how we delete all rows of the table.
Thanks, this was exactly what I wanted. As suggested by Rajendiran, it would be great if you can provide a small explanation, so that the non-SQL experts can understand.