Oracle: How to delete Duplicate rows from a table




There are many ways to delete duplicate rows from a table, here is one of simple way

   DELETE FROM Mytable WHERE rowid Not In (SELECT min(rowid) FROM Mytable  GROUP BY Column1);

In the sub query we  Select a unique rowid from all the rowid’s ,It can be using any one of  MAX, MIN functions  and the group by clause should include all the UNIQUE columns we desire. If we have a composite primary key on column1 and Column2  then the group by should be group by Column1,column2

The the sub query returns one record for the duplicate ID’s and I delete all of them that are not in the sub query and that deletes all the duplicate rows from the database.

SocialTwist Tell-a-Friend
 

Leave a Reply