Oracle查询重复数据并删除,只保留一条记录
2016-01-11 14:09
686 查看
【转】http://www.uncletoo.com/html/oracle/1101.html
1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断
select * from 表 where Id in (select Id from 表 group by Id having count(Id) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(Id)来判断,只留有rowid最小的记录
DELETE from 表 WHERE (id) IN ( SELECT id FROM 表 GROUP BY id HAVING COUNT(id) > 1) AND ROWID NOT IN (SELECT MIN(ROWID) FROM
表 GROUP BY id HAVING COUNT(*) > 1);
3、查找表中多余的重复记录(多个字段)
select * from 表 a where (a.Id,a.seq) in(select Id,seq from 表 group by Id,seq having count(*) > 1)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select
min(rowid) from 表 group by Id,seq having count(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in
(select min(rowid) from 表 group by Id,seq having count(*)>1)
1、查找表中多余的重复记录,重复记录是根据单个字段(Id)来判断
select * from 表 where Id in (select Id from 表 group by Id having count(Id) > 1)
2、删除表中多余的重复记录,重复记录是根据单个字段(Id)来判断,只留有rowid最小的记录
DELETE from 表 WHERE (id) IN ( SELECT id FROM 表 GROUP BY id HAVING COUNT(id) > 1) AND ROWID NOT IN (SELECT MIN(ROWID) FROM
表 GROUP BY id HAVING COUNT(*) > 1);
3、查找表中多余的重复记录(多个字段)
select * from 表 a where (a.Id,a.seq) in(select Id,seq from 表 group by Id,seq having count(*) > 1)
4、删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in (select
min(rowid) from 表 group by Id,seq having count(*)>1)
5、查找表中多余的重复记录(多个字段),不包含rowid最小的记录
select * from 表 a where (a.Id,a.seq) in (select Id,seq from 表 group by Id,seq having count(*) > 1) and rowid not in
(select min(rowid) from 表 group by Id,seq having count(*)>1)
相关文章推荐
- oracle 学习
- dos下,sqlplus导入导出出oracle数据库_用户和表
- Oracle数据库,实例,表空间,用户,表之间的关系简析
- MyBatis JdbcType 与Oracle、MySql数据类型对应关系详解
- ogg installation
- DOS下导入dmp文件到Oracle数据库
- 恢复oracle数据到以前的某个时间点
- oracle安装、配置、卸载、错误解决
- ORA-01033: ORACLE initialization or shutdown in progress (DBD ERROR: OCISess
- Oracle查询锁表以及杀会话或系统进程来解除锁表操作
- 关于Oracle、SqlServer 的sql递归查询
- oracle只读模式
- Oracle数据库order by排序之null值处理方法
- Cannot load JDBC driver class 'oracle.jdbc.driver.OracleDriver'
- oracle启动限制模式
- Oracle
- ORACLE中MINUS,INTERSECT和UNION ALL图解
- ORACLE索引
- Oracle undo表空间爆满的解决
- 利用Oracle外部表监控文件系统的空间使用率