Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to delete duplicate records in a table

Author  Topic 

manibad
Starting Member

9 Posts

Posted - 2012-10-04 : 16:43:29
I have a table named dup and in that i have to columns namely ID and Name.The values in the table are
ID Name
1 M
1 M
1 M
1 M
1 M

My aim is to delete the duplicated records and keep the distinct record.That is i gotta to delete 4 out of 5 rows and keep the rest.

How is this possible?
Pls give ur methods and explanations

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-10-04 : 17:02:36
yep. do like


DELETE t
FROM
(SELECT ROW_NUMBER() OVER (PARTITION BY ID,Name ORDER BY ID) AS Seq
FROM Table
)t
WHERE Seq>1



------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -