oracle 删除重复记录的高效方法

时间:2021-02-09 06:29:24

1、小部分删除重复

 DELETE T
  WHERE (COL1,COL2) IN
  (SELECT COL1,COL2 FROM T GROUP BY COL1,COL2 HAVING COUNT(*) > 1)
  AND
  ROWID NOT IN
  (SELECT MIN(ROWID) FROM T GROUP BY COL1,COL2 HAVING COUNT(*) > 1)
  
  2、大部份记录有重复记录
  
  DELETE T WHERE ROWID NOT IN
  (SELECT MIN(ROWID) FROM T GROUP BY COL1,COL2)
  
  3、其他写法
  
  DELETE T WHERE ROWID IN
  (SELECT A.ROWID FROM T A,T B
  WHERE A.COL1=B.COL1 AND A.COL2 = B.COL2 AND A.ROWID > B.ROWID)