ORACLE 去除多余的重复记录语句

一,去除多余的重复记录,以下以判断a字段,如果字段相同则记录相同
1、使用 rowid的方式
①正常版

delete from stu
where
a in (select a from stu group by a having count(a)>1)
and
rowid not in (select min(rowid) from people group by a having count(a)>1);

② 简便版

 delete from stu
 where rowid not in (select min(rowid) from stu group by a);

③ 使用表连接和 rowid 的方式

delete from stu t1 
where rowid not in (select min(rowid) from stu t2 where t1.a=t2.a);

二,以多个字段判定记录相同,原理相同(如 a,b 字段)

delete from stu
where
stu.a,stu.b in (select a,b from stu group by a,b having count(*)>1)
and
rowid not in (select min(rowid) from people group by a,b having count(a)>1);
 delete from stu
 where rowid not in (select min(rowid) from stu group by a,b);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值