查询某些字段相同的记录 如:查询col1与col2值相同的记录: select a.* from table1 a, table1 b where a.id &l
查询某些字段相同的记录
如:查询col1与col2值相同的记录:
select a.* from table1 a, table1 b where a.id <> b.id and a.col1 = b.col1 and a.col2 = b.col2;
根据oracle自带的rowid属性进行判断是否存在重复记录。
rowid伪列用于唯一标识物理位置的表行,当用insert插入数据时,会自动生成rowid,与数据一起存放,形如:AAAL=XAAAEAAAAA。
select * from table1 a where rowid!=
(select max(rowid) from table1 b where a.col1 = b.col1 and a.col2 = b.col2;
保留rowid最大的记录:
delete from table1 a where rowid!=
(select max(rowid) from table1 b where a.col1 = b.col1 and a.col2 = b.col2;
select * from table1 a where (a.col1,a.col2) in
(select col1,col2 from table1 group by col1,col2 having count(*)>1)
删除表中多余的重复记录(多个字段),只保留rowid最小的记录。
delete from table1 a where (a.col1,a.col2) in
(select col1,col2 from table1 group by col1,col2 having count(*)>1)
and rowid not in
(select min(rowid) from table1 group by col1,col2 having count(*)>1)
--结束END--
本文标题: Oracle去除重复数据
本文链接: https://www.lsjlt.com/news/147986.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0