SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to delete duplicate records in a table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

manibad
Starting Member

9 Posts

Posted - 10/04/2012 :  16:43:29  Show Profile  Reply with Quote
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

India
52325 Posts

Posted - 10/04/2012 :  17:02:36  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000