網站首頁 編程語言 正文
查詢某些字段相同的記錄
如:查詢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;
2、刪數據:
保留rowid最大的記錄:
delete from table1 a where rowid!=
(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)
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)
原文鏈接:https://www.cnblogs.com/springsnow/p/9394906.html
相關推薦
- 2022-11-06 在Centos7中使用vscode和gdb調試PG插件的方法_C 語言
- 2023-03-28 Python中的len()函數是什么意思_python
- 2023-04-18 antd中form表單的wrapperCol和labelCol問題詳解_React
- 2023-06-16 C語言中如何在結構體內定義函數_C 語言
- 2022-09-24 Pytorch實現邏輯回歸分類_python
- 2022-12-12 flutter自定義InheritedProvider實現狀態管理詳解_Android
- 2023-07-13 react中的useRef的使用
- 2022-11-15 簡單實現Android應用的啟動頁_Android
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支