SQL Delete Duplicate Records

I ran into the issue today with a client where their data was messed up with duplicate data (but different identity seeds) The following code only works when there is an identity seed. Remember to inlcude all the columns that would indicate a duplicate in the GROUP BY.

DELETE FROM MyTable WHERE ID NOT IN ( SELECT MAX(ID) FROM MyTable GROUP BY Col1, Col2)

POSTED BY Divergence Hosting on Mar 14 under SQL

Leave a Comment

If you would like to make a comment, please fill out the form below.

Name (required)

Email (required)

Website

Comments

Copyright Divergence Hosting Technical Blog | Powered by WordPress | Using the GreenTech Theme

SEO Powered by Platinum SEO from Techblissonline