当前位置:网站首页>Advanced learning of MySQL -- basics -- multi table query -- subquery
Advanced learning of MySQL -- basics -- multi table query -- subquery
2022-07-07 00:34:00 【Magic pig 9898】
Concept
SQL Nested in statement select sentence
The external statement of a subquery can be insert/update/delete/select Any one of .
That is said , DML and DQL You can subquery
Depending on the results of the subquery , It is divided into
Scalar subquery
The commonly used operator is : > < >= <= <>
The result is a single value
for example :
Query the information of all employees in the sales department select * from emp where dept_id =
(select id from dept where name = ' The sales department ');
This is scalar subquery
Column query
The result is a column ( Are some values of a field , In other words , Multiple scalars )
Let's first look at a few operators
The operator | explain |
---|---|
in | Within the specified set , A commonplace |
not in | Not within the specified range |
any/some | The subquery returns to the list , Any one can be satisfied |
all | The sub query return list must all meet |
for example :
Query all employee information of sales department and marketing department select * from emp where dept_id in
(select id from dept where name = ' The sales department ' or name = ' The Marketing Department ');
This is the column subquery
Another example is :
Check the information of employees whose salaries are higher than those of everyone in the finance department select * from emp where salary > all
(select salary from emp where dept_id =
(select id from dept where name = ' Finance Department ') );
Another example is :
Query the information of employees with higher wages than any one in the R & D department select * from emp where salary > some
(select salary from emp where dept_id =
(select id from dept where name = ' R & D department ') );
Line sub query
The result is one line ( Multiple fields , In other words , Single scalar Group )
Common operators := <> in not in
for example :
Query the same employee information as Xiaobai's salary and the leader select * from emp where (salary , managerid) =
(select salary , managerid from emp where name = ' The small white ');
Table sub query
The result is multiple rows and columns ( There is more than one scalar Group )
Common operators : in
for example :
Query and Xiaobai , Xiaohei's position and the information of employees with the same salary select * from emp where (job, salary) in
(select job , salary from emp where name = ' The small white ' or name = ' Little black ');
Another example is :
The entry time is ’2001-01-06’ Later employee information , And its department information select e.* , d.* from
(select * from emp where entrydate > '2001-01-06' ) e
left outer join
dept d
on e.dept_id = d.id ;
According to the location of subquery , It is divided into
select after
from after
where after
边栏推荐
- Mujoco produces analog video
- The way of intelligent operation and maintenance application, bid farewell to the crisis of enterprise digital transformation
- Leecode brush questions record sword finger offer 43 The number of occurrences of 1 in integers 1 to n
- AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
- [daily problem insight] prefix and -- count the number of fertile pyramids in the farm
- 如何判断一个数组中的元素包含一个对象的所有属性值
- Policy Gradient Methods
- 1000 words selected - interface test basis
- JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
- [2022 the finest in the whole network] how to test the interface test generally? Process and steps of interface test
猜你喜欢
Data analysis course notes (V) common statistical methods, data and spelling, index and composite index
Designed for decision tree, the National University of Singapore and Tsinghua University jointly proposed a fast and safe federal learning system
Jenkins' user credentials plug-in installation
iMeta | 华南农大陈程杰/夏瑞等发布TBtools构造Circos图的简单方法
专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
Core knowledge of distributed cache
工程师如何对待开源 --- 一个老工程师的肺腑之言
Everyone is always talking about EQ, so what is EQ?
[automated testing framework] what you need to know about unittest
X.509 certificate based on go language
随机推荐
基于GO语言实现的X.509证书
js导入excel&导出excel
St table
Sword finger offer 26 Substructure of tree
华为mate8电池价格_华为mate8换电池后充电巨慢
2021 SASE integration strategic roadmap (I)
On February 19, 2021ccf award ceremony will be held, "why in Hengdian?"
Wechat applet UploadFile server, wechat applet wx Uploadfile[easy to understand]
Model-Free Control
Pytest multi process / multi thread execution test case
MySQL learning notes (mind map)
[boutique] Pinia Persistence Based on the plug-in Pinia plugin persist
File and image comparison tool kaleidoscope latest download
Data analysis course notes (III) array shape and calculation, numpy storage / reading data, indexing, slicing and splicing
Mujoco produces analog video
How to use vector_ How to use vector pointer
37 pages Digital Village revitalization intelligent agriculture Comprehensive Planning and Construction Scheme
ldap创建公司组织、人员
Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
Things like random