網站首頁 編程語言 正文
子查詢關鍵字-ALL、ANY、SOME、IN、EXISTS
ALL
select from where c > all(查詢語句)
等價于
select from where c > result1 and c > result2 and c > result3
特點:
1:all與子查詢返回的所有值比較為true 則返回true
2:ALL可以與= > < >= <= <>結合使用
3:all表示指定列中的值必須要大于子查詢集中的每一個值
eg:查詢年齡大于'1003'部門所有年齡的員工信息
select * from emp3 where age > all(select age from emp3 where dept_id='1003');
查詢不屬于任何一個部門的員工信息
select * from emp3 where dept_id != all(select deptno from dept3);
ANY SOME
select from where c > any(查詢語句)
等價于
select from where c > result1 or c > result2 or c > result3
特點:
1:any與子查詢返回的所有值比較為true 則返回true
2:any可以與= > < >= <= <>結合使用
3:any表示指定列中的值要大于子查詢集中任意的一個值
eg:查詢年齡大于'1003'部門任意一個員工年齡的員工信息
select * from emp3 where age > any(select age from emp3 where dept_id='1003');
some和any的作用是一樣的,some可以理解為是any的別名
IN
select from c in (查詢語句)
等價于
select from where c =result1 or c=result2 or c=result3
特點:
in關鍵字,用于判斷某個記錄的值,是否在指定的集合中
在in關鍵字前面加上not可以將條件反過來
eg:查詢研發部和銷售部的員工信息,包括員工工號,員工名字
select c.cid,c.name from cmp3 c where dept_id in (select deptno from dept3 where name='研發部' or name='銷售部');
EXISTS
select from where exists(查詢語句)
特點:
該子查詢如果"有數據結果"(至少返回一行數據),則該EXISTS()的結果為true 外層查詢執行
該子查詢如果"沒有數據結果"(沒有任何數據返回),則該EXISTS()的結果為false 外層查詢不執行
注意:EXISTS關鍵字,比in關鍵字的運算效率高,在實際開發中 特別是數據量大的時候推薦使用exists關鍵字
eg:查詢公司是否有大于60歲的員工,有則輸出
select * from epm3 a where exists (select * from emp3 b where a.age>60)
查詢所屬部門的員工信息
select *from dept3 a where exists (select * from emp3 b where a.deptno=b.dept_id)
原文鏈接:https://timefriends.blog.csdn.net/article/details/123676775
相關推薦
- 2022-06-28 C#回收機制之資源回收托管_C#教程
- 2022-05-23 ELK與Grafana聯合打造可視化監控來分析nginx日志_nginx
- 2022-10-14 ‘configurationClass‘ must be assignable to [org.hi
- 2022-12-06 深入了解Rust?結構體的使用_Rust語言
- 2022-06-28 react18中react-redux狀態管理的實現_React
- 2022-09-22 lex yacc與C++編寫代碼解析字符串代碼示例
- 2023-07-07 根據文件后綴名稱獲取contentType,其中Minio上傳文件會用到contentType
- 2022-11-11 Python深度學習之FastText實現文本分類詳解_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同步修改后的遠程分支