Oracle數據庫刪除表中的重復數據,只保留其中的一條,以兩個字段為例,提供兩種方法
①、直接delete重復的數據
delete from table_name t1 where (t1.col1, t1.col2) in (select col1, col2 from table_name group by col1, col2 having count(*) > 1) and t1.rowid in (select min(rowid) from table_name group by col1, col2 having count(*) > 1);
②、查詢出所有不重復的數據,入到一張中間表中,然后把原表的數據清空,最后把中間表的數據入到原表中
--數據入到中間表中 insert into table_mid_name select t1.* from table_name t1 where t1.rowid in (select min(rowid) from table_name group by col1, col2 ) ; --清除原表數據 truncate table table_name ; --數據入到原表中 insert into table_name select * from table_mid_name ;