当前位置:网站首页>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
边栏推荐
- How can computers ensure data security in the quantum era? The United States announced four alternative encryption algorithms
- Policy Gradient Methods
- Oracle EMCC 13.5 environment in docker every minute
- 准备好在CI/CD中自动化持续部署了吗?
- A way of writing SQL, update when matching, or insert
- 2022 PMP project management examination agile knowledge points (9)
- PXE server configuration
- 2022年PMP项目管理考试敏捷知识点(9)
- @TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
- Article management system based on SSM framework
猜你喜欢
Pytest multi process / multi thread execution test case
基於GO語言實現的X.509證書
一图看懂对程序员的误解:西方程序员眼中的中国程序员
三维扫描体数据的VTK体绘制程序设计
Racher integrates LDAP to realize unified account login
互动滑轨屏演示能为企业展厅带来什么
Business process testing based on functional testing
The way of intelligent operation and maintenance application, bid farewell to the crisis of enterprise digital transformation
什么是响应式对象?响应式对象的创建过程?
DAY TWO
随机推荐
openresty ngx_ Lua subrequest
Hero League | King | cross the line of fire BGM AI score competition sharing
Everyone is always talking about EQ, so what is EQ?
SQL的一种写法,匹配就更新,否则就是插入
【vulnhub】presidential1
Google, Baidu and Yahoo are general search engines developed by Chinese companies_ Baidu search engine URL
Amazon MemoryDB for Redis 和 Amazon ElastiCache for Redis 的内存优化
Three application characteristics of immersive projection in offline display
What is AVL tree?
Command line kills window process
ldap创建公司组织、人员
Interesting wine culture
vector的使用方法_vector指针如何使用
[vector retrieval research series] product introduction
How to set encoding in idea
Uniapp uploads and displays avatars locally, and converts avatars into Base64 format and stores them in MySQL database
C language input / output stream and file operation [II]
A way of writing SQL, update when matching, or insert
PostgreSQL highly available repmgr (1 master 2 slave +1witness) + pgpool II realizes master-slave switching + read-write separation
Imeta | Chen Chengjie / Xia Rui of South China Agricultural University released a simple method of constructing Circos map by tbtools