How to delete all duplicate rows and leave only one of them, in Oracle? DELETE FROM my_table WHERE rowid not in (SELECT MIN(rowid) FROM my_table GROUP BY column1, column2, column3...) ; Where column1, column2, etc. is the key you want to use. Relative links: Remove duplicate rows in ... Read more
Tag Archives: Remove duplicate rows
Remove duplicate rows in MySQL
The primary key: id, the unique columns: col_1, col_2, col_3 . You can use a temporary table, like: create temporary table temp_table (id int); insert temp_table (id) select id from your_table t1 where exists ( select * from your_table t2 ... Read more
Remove duplicate rows in SQL Server
Assuming no nulls, you GROUP BY the unique columns (eg. col_1, col_2, col_3), and SELECT the MIN (or MAX) Row ID (eg. row_id) as the row to keep. Then, delete everything that didn’t have a row id: DELETE my_table FROM my_table LEFT OUTER JOIN ( SELECT MIN(row_id) as row_id, col_1, ... Read more