当前位置:网站首页>MySQL connection query and subquery
MySQL connection query and subquery
2022-07-02 03:14:00 【sshi9】
Link query
Link query : It can also be called cross table query , You need to associate multiple tables to query
Join query classification
According to the age of grammar , Include :
SQL92
SQL99
It is divided according to the connection mode of the table , Include :
Internal connection :
Equivalent connection
Non equivalent connection
Self join
External connection :
The left outer join ( Left connection )
Right connection ( The right connection )
Full connection
Cartesian product : When two tables are connected for query , There are no conditions to limit , The number of final query results is the product of the number of records in the two tables .
Example
Display information of each employee , And display the name of the Department
The right thing to do is
The above query is also called “ Internal connection ”, Query only equal data ( Data with equal connection conditions )
Internal and external connections
Internal connection :
hypothesis A and B Tables to connect , If you use an internal connection , Anyone who A Table and B The table can be queried by matching the records on the table , This is the inner link .AB There is no difference between the two tables , The two tables are equal .
External connection :
hypothesis A and B Tables to connect , If you use external connections ,AB One of the two tables is the main table , A watch is a secondary watch , The main query is in the main table The data of , With the side table , When the data in the secondary table does not match the data in the primary table , The secondary table automatically simulates NULL To match .
External connection classification
The left outer join ( Left connection ): The table on the left is the main table .
Right connection ( The right connection ): The table on the right is the main table .
Example
Show employee information , And display the name of the Department , If a department has no employees , Then the Department must also show
The right connection
Left connection
The above two queries have the same effect
Subquery
select Nested in statements select sentence , Nested select Statements are subqueries .
Example
Find out who has a higher salary than the average employee , Need to display employee number , Employee name , salary
Realize the idea :
- Get an average salary
select avg(sal) from emp;
2. Employees who earn more than the average salary
select empno, ename, sal from emp where sal > (select avg(sal) from emp);
边栏推荐
- Mathematical calculation in real mode addressing
- MSI announced that its motherboard products will cancel all paper accessories
- 表单自定义校验规则
- Halcon image rectification
- Continuous assignment of Verilog procedure
- Global and Chinese market of gynaecological health training manikin 2022-2028: Research Report on technology, participants, trends, market size and share
- Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Uniapp uses canvas to generate posters and save them locally
- [C Advanced] brother Peng takes you to play with strings and memory functions
- ZABBIX API creates hosts in batches according to the host information in Excel files
猜你喜欢
Discrimination between sap Hana, s/4hana and SAP BTP
[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)
Verilog 状态机
2022-2028 global manual dental cleaning equipment industry research and trend analysis report
小米青年工程师,本来只是去打个酱油
Continuous assignment of Verilog procedure
SAML2.0 笔记(一)
How to develop digital collections? How to develop your own digital collections
verilog 并行块实现
[staff] diacritical mark (ascending sign | descending sign B | double ascending sign x | double descending sign BB)
随机推荐
verilog REG 寄存器、向量、整数、实数、时间寄存器
Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
The video number will not be allowed to be put on the shelves of "0 yuan goods" in the live broadcasting room?
MongoDB非關系型數據庫
Redis set command line operation (intersection, union and difference, random reading, etc.)
Calculation of page table size of level 2, level 3 and level 4 in protection mode (4k=4*2^10)
Stdref and stdcref
PMP personal sprint preparation experience
Just a few simple steps - start playing wechat applet
Stack - es - official documents - filter search results
SAML2.0 笔记(一)
GB/T-2423.xx 环境试验文件,整理包括了最新的文件里面
Baohong industry | four basic knowledge necessary for personal finance
The capacity is upgraded again, and the new 256gb large capacity specification of Lexar rexa 2000x memory card is added
Grpc快速实践
About DNS
3124. Word list
Framing in data transmission
/silicosis/geo/GSE184854_scRNA-seq_mouse_lung_ccr2/GSE184854_RAW/GSM5598265_matrix_inflection_demult
Form custom verification rules