網站首頁 編程語言 正文
查詢某些字段相同的記錄
如:查詢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
相關推薦
- 2024-02-27 Action獲取表單提交數據
- 2023-07-25 SpringBoot整合Quartz以及異步調用
- 2022-11-01 Go語言框架快速集成限流中間件詳解_Golang
- 2022-03-22 C++運算符重載限制介紹_C 語言
- 2022-08-15 Python利用Selenium實現自動化驗證登錄
- 2022-06-25 pytorch中permute()函數用法補充說明(矩陣維度變化過程)_python
- 2022-10-02 Linux?Shell?自動交互功能實現_linux shell
- 2022-11-17 一文詳解測試Python讀寫xml配置文件_python
- 最近更新
-
- 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同步修改后的遠程分支