C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




Different ways of deleting duplicate records in a table.


Posted Date: 12 Jun 2008    Resource Type: Code Snippets    Category: SQL

Posted By: ashwin       Member Level: Bronze
Rating:     Points: 5



"Delete duplicate records from table.". This is one of the frequently asked questions in sql. I am providing couple of ways to delete duplicate records in a table.
For SQL 2000:


DELETE t FROM
(
SELECT (SELECT COUNT(*) + 1 FROM Table WHERE code=t.code AND ID > t.ID) AS RowNo,
code,
Col2,
Col3,
Col4
FROM Table t
)t
WHERE t.RowNo<>1

For SQL 2005:

DELETE t FROM
(
SELECT ROW_NUMBER() OVER(PARTITION BY code ORDER BY ID DESC) AS RowNo
FROM Table
)t
WHERE t.RowNo<>1


or

DELETE x
FROM table1 AS x
LEFT JOIN (
SELECT MAX(ID) AS ID
FROM table1
) AS y ON y.ID = x.ID
WHERE y.ID IS NULL





Responses


No responses found. Be the first to respond and make money from revenue sharing program.

Feedbacks      
Popular Tags   What are tags ?   Search Tags  
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to select TOP N number of columns
Previous Resource: How to write a function to get Last Day of the month
Return to Discussion Resource Index
Post New Resource
Category: SQL


Post resources and earn money!
 
Related Resources



dotNet Slackers   BizTalk Adaptors    Web Design

conference call

Contact Us    Privacy Policy    Terms Of Use