当前位置:网站首页>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);

边栏推荐
- Use blocking or non blocking for streamline
- 3048. Number of words
- Common means of modeling: aggregation
- After marriage
- Rotating frame target detection mmrotate v0.3.1 learning model
- IPhone 6 plus is listed in Apple's "retro products" list
- 2022-2028 global human internal visualization system industry research and trend analysis report
- 高并发场景下缓存处理方案
- Gradle notes
- uniapp 使用canvas 生成海报并保存到本地
猜你喜欢

Share the basic knowledge of a common Hongmeng application

After marriage

Uniapp uses canvas to generate posters and save them locally

About DNS
![[JSON] gson use and step on the pit](/img/86/6ee2971715e0d29008a4b7b1a7aa45.jpg)
[JSON] gson use and step on the pit

Form custom verification rules
![[road of system analyst] collection of wrong topics in enterprise informatization chapter](/img/c4/0bb4823ca85c440b4e0587a91b2585.jpg)
[road of system analyst] collection of wrong topics in enterprise informatization chapter

MongoDB非關系型數據庫

Design details of SAP e-commerce cloud footernavigationcomponent

PHP notes - use Smarty to set public pages (include, if, else, variable settings)
随机推荐
终日乾乾,夕惕若厉
Stdref and stdcref
Gradle notes
Verilog 过程赋值 区别 详解
MSI announced that its motherboard products will cancel all paper accessories
Verilog parallel block implementation
C#联合halcon脱离halcon环境以及各种报错解决经历
[staff] pitch representation (bass clef | C1 36 note pitch representation | C2 48 note pitch representation | C3 60 note pitch representation)
3048. Number of words
Halcon image rectification
Continuous assignment of Verilog procedure
Cache processing scheme in high concurrency scenario
Intersection of Venn graph
buu_ re_ crackMe
Force deduction daily question 540 A single element in an ordered array
Common means of modeling: aggregation
GSE104154_ scRNA-seq_ fibrotic MC_ bleomycin/normalized AM3
verilog REG 寄存器、向量、整数、实数、时间寄存器
/silicosis/geo/GSE184854_ scRNA-seq_ mouse_ lung_ ccr2/GSE184854_ RAW/GSM5598265_ matrix_ inflection_ demult
4. Find the median of two positive arrays