ORACLE开发:Oracle去除重复数据
查询某些字段相同的记录
如:查询col1与col2值相同的记录:
select a.* from table1 a, table1 b where a.id <> b.id and a.col1 = b.col1 and a.col2 = b.col2;
一、用rowid方法:
根据oracle自带的rowid属性进行判断是否存在重复记录。
rowid伪列用于唯一标识物理位置的表行,当用insert插入数据时,会自动生成rowid,与数据一起存放,形如:AAAL=XAAAEAAAAA。
1、查数据:
select * from table1 a where rowid!=
(select max(rowid) from table1 b where a.col1 = b.col1 and a.col2 = b.col2;
(select max(rowid) from table1 b where a.col1 = b.col1 and a.col2 = b.col2;
2、删数据:
保留rowid最大的记录:
delete from table1 a where rowid!=
(select max(rowid) from table1 b where a.col1 = b.col1 and a.col2 = b.col2;
(select max(rowid) from table1 b where a.col1 = b.col1 and a.col2 = b.col2;
二、group by 方法:
1、查数据:
select * from table1 a where (a.col1,a.col2) in
(select col1,col2 from table1 group by col1,col2 having count(*)>1)
(select col1,col2 from table1 group by col1,col2 having count(*)>1)
2、删数据:
删除表中多余的重复记录(多个字段),只保留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)
(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)
到此这篇关于ORACLE开发:ORACLE开发:ORACLE开发:Oracle去除重复数据的文章就介绍到这了。希望对大家的学习有所帮助,也希望大家多多支持。
我想要获取技术服务或软件
服务范围:MySQL、ORACLE、SQLSERVER、MongoDB、PostgreSQL 、程序问题
服务方式:远程服务、电话支持、现场服务,沟通指定方式服务
技术标签:数据恢复、安装配置、数据迁移、集群容灾、异常处理、其它问题
沟通购买:QQ咨询 淘宝咨询 微信咨询 淘宝店铺
版权申明及联系服务范围:MySQL、ORACLE、SQLSERVER、MongoDB、PostgreSQL 、程序问题
服务方式:远程服务、电话支持、现场服务,沟通指定方式服务
技术标签:数据恢复、安装配置、数据迁移、集群容灾、异常处理、其它问题
沟通购买:QQ咨询 淘宝咨询 微信咨询 淘宝店铺
本站部分文章参考或来源于网络,如有侵权请联系站长。本站提供相关远程技术服务,有需要可联系QQ
数据库远程运维 » ORACLE开发:Oracle去除重复数据