当前位置:网站首页>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
边栏推荐
- The difference between redirectto and navigateto in uniapp
- GPIO简介
- dynamic programming
- TypeScript中使用类型别名
- Mujoco finite state machine and trajectory tracking
- GPIO簡介
- DAY ONE
- Use package FY in Oracle_ Recover_ Data. PCK to recover the table of truncate misoperation
- Geo data mining (III) enrichment analysis of go and KEGG using David database
- Everyone is always talking about EQ, so what is EQ?
猜你喜欢
Testers, how to prepare test data
37 page overall planning and construction plan for digital Village revitalization of smart agriculture
Devops can help reduce technology debt in ten ways
What is AVL tree?
Mujoco Jacobi - inverse motion - sensor
DAY FOUR
Liuyongxin report | microbiome data analysis and science communication (7:30 p.m.)
The way of intelligent operation and maintenance application, bid farewell to the crisis of enterprise digital transformation
37 pages Digital Village revitalization intelligent agriculture Comprehensive Planning and Construction Scheme
2022年PMP项目管理考试敏捷知识点(9)
随机推荐
PXE server configuration
509 certificat basé sur Go
Rails 4 asset pipeline vendor asset images are not precompiled
Mujoco Jacobi - inverse motion - sensor
Use Yum or up2date to install the postgresql13.3 database
Leecode brush questions record interview questions 32 - I. print binary tree from top to bottom
[CVPR 2022] semi supervised object detection: dense learning based semi supervised object detection
Racher integrates LDAP to realize unified account login
Introduction au GPIO
JWT signature does not match locally computed signature. JWT validity cannot be asserted and should
Model-Free Prediction
Idea automatically imports and deletes package settings
@TableId can‘t more than one in Class: “com.example.CloseContactSearcher.entity.Activity“.
Three application characteristics of immersive projection in offline display
2021 SASE integration strategic roadmap (I)
数据运营平台-数据采集[通俗易懂]
工程师如何对待开源 --- 一个老工程师的肺腑之言
Interesting wine culture
How engineers treat open source -- the heartfelt words of an old engineer
陀螺仪的工作原理