当前位置:网站首页>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
边栏推荐
- Lombok 同时使⽤ @Data 和 @Builder 的坑,你中招没?
- [CVPR 2022] target detection sota:dino: Detr with improved detecting anchor boxes for end to end object detection
- Compilation of kickstart file
- 【CVPR 2022】目标检测SOTA:DINO: DETR with Improved DeNoising Anchor Boxes for End-to-End Object Detection
- 专为决策树打造,新加坡国立大学&清华大学联合提出快速安全的联邦学习新系统
- openresty ngx_ Lua subrequest
- Pytest multi process / multi thread execution test case
- What is AVL tree?
- 【向量检索研究系列】产品介绍
- Three application characteristics of immersive projection in offline display
猜你喜欢

Idea automatically imports and deletes package settings

How to set encoding in idea

On February 19, 2021ccf award ceremony will be held, "why in Hengdian?"

2022年PMP项目管理考试敏捷知识点(9)

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

File and image comparison tool kaleidoscope latest download

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

Understand the misunderstanding of programmers: Chinese programmers in the eyes of Western programmers

三维扫描体数据的VTK体绘制程序设计

DAY THREE
随机推荐
Why should a complete knapsack be traversed in sequence? Briefly explain
Mujoco second order simple pendulum modeling and control
C language input / output stream and file operation [II]
Are you ready to automate continuous deployment in ci/cd?
Wechat applet UploadFile server, wechat applet wx Uploadfile[easy to understand]
一图看懂对程序员的误解:西方程序员眼中的中国程序员
Use Yum or up2date to install the postgresql13.3 database
Leecode brushes questions and records interview questions 01.02 Determine whether it is character rearrangement for each other
A way of writing SQL, update when matching, or insert
2022/2/12 summary
GPIO簡介
DAY FIVE
Encryption algorithm - password security
What is web penetration testing_ Infiltration practice
DAY ONE
Geo data mining (III) enrichment analysis of go and KEGG using David database
Use mujoco to simulate Cassie robot
【向量检索研究系列】产品介绍
vector的使用方法_vector指针如何使用
基於GO語言實現的X.509證書