当前位置:网站首页>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' ) eleft outer joindept don e.dept_id = d.id ;
According to the location of subquery , It is divided into
select after
from after
where after
边栏推荐
- 【vulnhub】presidential1
- kubernetes部署ldap
- Model-Free Prediction
- Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers
- Mujoco finite state machine and trajectory tracking
- @TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
- DAY ONE
- 谷歌百度雅虎都是中国公司开发的通用搜索引擎_百度搜索引擎url
- 华为mate8电池价格_华为mate8换电池后充电巨慢
- Value Function Approximation
猜你喜欢

Memory optimization of Amazon memorydb for redis and Amazon elasticache for redis

Introduction to GPIO

基于GO语言实现的X.509证书

X.509 certificate based on go language

GEO数据挖掘(三)使用DAVID数据库进行GO、KEGG富集分析

Everyone is always talking about EQ, so what is EQ?

Uniapp uploads and displays avatars locally, and converts avatars into Base64 format and stores them in MySQL database

St table

DAY ONE

Clipboard management tool paste Chinese version
随机推荐
37頁數字鄉村振興智慧農業整體規劃建設方案
1000 words selected - interface test basis
How to set encoding in idea
MySQL master-slave multi-source replication (3 master and 1 slave) setup and synchronization test
System activity monitor ISTAT menus 6.61 (1185) Chinese repair
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
X.509 certificate based on go language
刘永鑫报告|微生物组数据分析与科学传播(晚7点半)
DAY ONE
Sword finger offer 26 Substructure of tree
What is a responsive object? How to create a responsive object?
Operation test of function test basis
uniapp中redirectTo和navigateTo的区别
Mujoco finite state machine and trajectory tracking
【CVPR 2022】目标检测SOTA:DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection
Data operation platform - data collection [easy to understand]
Cross-entrpy Method
Leecode brushes questions and records interview questions 01.02 Determine whether it is character rearrangement for each other
js导入excel&导出excel
一图看懂对程序员的误解:西方程序员眼中的中国程序员