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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | 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
 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
52326 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  
 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.05 seconds. Powered By: Snitz Forums 2000