Tuesday, May 16, 2017

SQL - Remove duplicate rows

Neat query to remove duplicate rows (MSSQL)

Assuming I have a table with auto-increment id

DELETE FROM MyTable
WHERE id NOT IN (SELECT MIN(id) FROM MyTable GROUP BY UniqueCol1, UniqueCol2);

No comments:

Related Posts Plugin for WordPress, Blogger...