oracle删除一个表内的重复数据,

时间:2023-03-09 09:14:32
oracle删除一个表内的重复数据,

查询以及删除一个数据库表内的重复数据。

1.查询表中的多余的重复记录,重复记录是根据单个字段来判断的。

select * from biao where id in (select id from biao group by id having count(id) >1 )

2.删除表中的多余的重复记录,重复记录是根据(id)来判断,只留rowid 最小值。

delete from  biao where id  in   ( select  id from biao group by id having count(id) )  and  rowid not in  ( select  min(rowid) from  biao group by id having count(id)>1 )

delete from xuesheng
where T_NAME in
(select T_NAME
from xuesheng
group by T_NAME, T_ADDRESS, T_PHONE, T_BIRTHDAY
having count(*) > 1) --重复数据
and rowid not in
(select max(rowid)
from xuesheng
group by T_NAME, T_ADDRESS, T_PHONE, T_BIRTHDAY
having count(*) > 1) --保留一条重复数据

3.删除表中重复的记录(多个字段),

delete from xuesheng
where T_NAME in
(select T_NAME
from xuesheng
group by T_NAME, T_ADDRESS, T_PHONE, T_BIRTHDAY
having count(*) > 1) --不保留重复数据

来自:https://www.cnblogs.com/252e/archive/2012/09/13/2682817.html