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)
Leave a Comment
If you would like to make a comment, please fill out the form below.