Wednesday, July 2, 2008

Delete duplicate rows in a table

To delete the duplicate rows from a table.

Method 1 :


create table newtable as (select distinct * from oldtable);

drop table oldtable;

rename newtable to oldtable;


Method 2:


DELETE FROM mytable t1
WHERE ROWID < (SELECT MAX (ROWID)
FROM mytable t2
WHERE t1.col1 = t2.col1 AND t1.col2 = t2.col2)