Thursday, November 22, 2012

Remove Duplicate Rows from DataBase in Sql Server

SELECT * FROM Tab_Test WHERE serial_num NOT IN (SELECT MIN(serial_num) FROM dbo.Tab_Test GROUP BY col1,col2)

serial_num is an auto indentity column

DELETE FROM Tab_Test WHERE serial_num NOT IN (SELECT MIN(serial_num) FROM dbo.Tab_Test GROUP BY col1,col2)

0 comments:

Post a Comment