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);

猜你喜欢

转载自blog.csdn.net/whiteblack_dream/article/details/75013830
今日推荐