Delete Duplicates

Hi I have a table and  need to identify duplicates by creating an unique key  by concatenating col1+Col2+col3 and then keep last occurring duplicate for each group of duplicates.

How can we achieve this?
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jim HornMicrosoft SQL Server Data DudeCommented:
Thre's really not enough details here to give you a rock-solid solution, but the article SQL Server Delete Duplicate Rows should give you a wompload of help.
Máté FarkasDatabase Developer and AdministratorCommented:
You don't need to concatenate keys.
You can do it this way:
        SELECT *, ROW_NUMBER() OVER(PARTITION BY Col1, Col2, Col3) Rn
        FROM dbo.YourTable
WHERE Rn > 1

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SrivAuthor Commented:
Mate your Answer keeps the first unique record and deletes the rest. however I need to keep the last unique record and delete the rest
Máté FarkasDatabase Developer and AdministratorCommented:
Ok, what is the definition of first record and last in your table?
SrivAuthor Commented:
Mate the above solution that you provided find duplicates and keeps first occurring (Ranked 1) duplicate and deletes other duplicates but my requirement is to keep the last ranked duplicate. We also have ID column which is identity column. We need to find  the duplicates and then based on each duplicate group we need to  keep the duplicate that has max ID column
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.