当前位置:网站首页>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
边栏推荐
- Supersocket 1.6 creates a simple socket server with message length in the header
- 基于SSM框架的文章管理系统
- 智能运维应用之道,告别企业数字化转型危机
- How to judge whether an element in an array contains all attribute values of an object
- 【vulnhub】presidential1
- What is a responsive object? How to create a responsive object?
- 英雄联盟|王者|穿越火线 bgm AI配乐大赛分享
- 互动滑轨屏演示能为企业展厅带来什么
- JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
- iMeta | 华南农大陈程杰/夏瑞等发布TBtools构造Circos图的简单方法
猜你喜欢

Article management system based on SSM framework

Win10 startup error, press F9 to enter how to repair?

互动滑轨屏演示能为企业展厅带来什么

2022/2/11 summary

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

从外企离开,我才知道什么叫尊重跟合规…

2022 PMP project management examination agile knowledge points (9)

What is AVL tree?

2022/2/10 summary
随机推荐
PXE server configuration
Use Yum or up2date to install the postgresql13.3 database
QT tutorial: creating the first QT program
DAY FIVE
48 page digital government smart government all in one solution
Value Function Approximation
File and image comparison tool kaleidoscope latest download
uniapp中redirectTo和navigateTo的区别
什么是响应式对象?响应式对象的创建过程?
Are you ready to automate continuous deployment in ci/cd?
Mujoco finite state machine and trajectory tracking
What is web penetration testing_ Infiltration practice
PostgreSQL highly available repmgr (1 master 2 slave +1witness) + pgpool II realizes master-slave switching + read-write separation
Use mujoco to simulate Cassie robot
AI超清修复出黄家驹眼里的光、LeCun大佬《深度学习》课程生还报告、绝美画作只需一行代码、AI最新论文 | ShowMeAI资讯日报 #07.06
PostgreSQL uses pgpool II to realize read-write separation + load balancing
Leecode brush question record sword finger offer 56 - ii Number of occurrences of numbers in the array II
How to use vector_ How to use vector pointer
Jenkins' user credentials plug-in installation
从外企离开,我才知道什么叫尊重跟合规…