07.03.08
Query to delete duplicate Records in SQL Server 2005
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
Vinodh said,
July 17, 2008 at 11:31 am
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.
dayananthan said,
July 18, 2008 at 5:42 am
Please provide one example as what exactly you want
chandra mohan said,
September 4, 2008 at 11:47 am
thanks your answer is right
but that is so complex
good luck
Rakis said,
November 19, 2008 at 10:07 am
Good One
Thanks!!!!!!!!
harinath clavib said,
January 2, 2009 at 8:54 pm
the query working well but need to understand i appreciate if could you explain about given query to delete the duplicate records.
Thank you
Govind said,
February 11, 2009 at 9:22 pm
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
webtips said,
March 10, 2009 at 3:58 am
good one…
I find two other method to solve the issue.
Delete Duplicate records in SQL Server
ramesh said,
August 20, 2009 at 9:08 am
very nice post.your solution solve my problem.