1. 程式人生 > >使用oracle刪除表中重復記錄

使用oracle刪除表中重復記錄

tro and ron 刪除重復 sele let card 刪除重復數據 name

(1)使用用rowid方法

查詢重復數據:select * from person a where rowid !=(select max(rowid) from person b where a.cardid=b.cardid and a.pname=b.pname);

刪除重復數據:delete from person a where rowid !=(select max(rowid) from person b where a.cardid=b.cardid and a.pname=b.pname);

(2)使用group by方法

查詢重復數據:select * from person where cardid in (select cardid from person group by cardid having count(cardid)>1);

刪除重復數據:delete from person where cardid in (select cardid from person group by cardid having count(cardid)>1) and rowid not in (select min(rowid) from person group by cardid having count(cardid)>1);

使用oracle刪除表中重復記錄