当前位置:网站首页>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);
边栏推荐
- Grpc快速实践
- V-model of custom component
- IPhone 6 plus is listed in Apple's "retro products" list
- GB/T-2423. XX environmental test documents, including the latest documents
- Possible causes of runtime error
- 4. Find the median of two positive arrays
- Verilog 状态机
- Start a business
- Grpc quick practice
- [JS reverse series] analysis of a customs publicity platform
猜你喜欢
Start a business
Discussion on related configuration of thread pool
Mongodb non relational database
MMSegmentation系列之训练与推理自己的数据集(三)
Jointly developed by nailing, the exclusive functions of glory tablet V7 series were officially launched
Just a few simple steps - start playing wechat applet
高并发场景下缓存处理方案
Golang configure export goprivate to pull private library code
Use usedeferredvalue for asynchronous rendering
JS <2>
随机推荐
Qualcomm platform WiFi -- Native crash caused by WiFi
创业了...
C # joint Halcon's experience of breaking away from Halcon environment and various error reporting solutions
Après le mariage
Force deduction daily question 540 A single element in an ordered array
2022-2028 global encryption software industry research and trend analysis report
Continuous assignment of Verilog procedure
Gradle 笔记
Stack - es - official documents - filter search results
C#聯合halcon脫離halcon環境以及各種報錯解决經曆
Gradle notes
/silicosis/geo/GSE184854_scRNA-seq_mouse_lung_ccr2/GSE184854_RAW/GSM5598265_matrix_inflection_demult
命名块 verilog
4. Find the median of two positive arrays
2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
Systemserver service and servicemanager service analysis
Possible causes of runtime error
Baohong industry | what misunderstandings should we pay attention to when diversifying investment
Principle of computer composition - interview questions for postgraduate entrance examination (review outline, key points and reference)
Find duplicates [Abstract binary / fast and slow pointer / binary enumeration]