Removing duplicate rows from table in Oracle

前端 未结 22 1896
醉话见心
醉话见心 2020-11-22 12:57

I\'m testing something in Oracle and populated a table with some sample data, but in the process I accidentally loaded duplicate records, so now I can\'t create a primary ke

22条回答
  •  礼貌的吻别
    2020-11-22 13:18

    For best performance, here is what I wrote :
    (see execution plan)

    DELETE FROM your_table
    WHERE rowid IN 
      (select t1.rowid from your_table  t1
          LEFT OUTER JOIN (
          SELECT MIN(rowid) as rowid, column1,column2, column3
          FROM your_table 
          GROUP BY column1, column2, column3
      )  co1 ON (t1.rowid = co1.rowid)
      WHERE co1.rowid IS NULL
    );
    

提交回复
热议问题