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

边栏推荐
- Share the basic knowledge of a common Hongmeng application
- 使用 useDeferredValue 进行异步渲染
- 2022-2028 global human internal visualization system industry research and trend analysis report
- Apple added the first iPad with lightning interface to the list of retro products
- Use usedeferredvalue for asynchronous rendering
- Continuous assignment of Verilog procedure
- 自定义组件的 v-model
- C#聯合halcon脫離halcon環境以及各種報錯解决經曆
- Verilog parallel block implementation
- Halcon image rectification
猜你喜欢
![[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)](/img/21/7bbf276b01f5a1056a22f5afc0af26.jpg)
[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)

Après le mariage

Cache processing scheme in high concurrency scenario

Design details of SAP e-commerce cloud footernavigationcomponent

After marriage

Addition without addition, subtraction, multiplication and division (simple difficulty)

2022-2028 global encryption software industry research and trend analysis report

Uniapp uses canvas to generate posters and save them locally

Mmsegmentation series training and reasoning their own data set (3)

Framing in data transmission
随机推荐
After marriage
GB/T-2423.xx 环境试验文件,整理包括了最新的文件里面
Après le mariage
Discrimination between sap Hana, s/4hana and SAP BTP
C # joint Halcon's experience of breaking away from Halcon environment and various error reporting solutions
MMSegmentation系列之训练与推理自己的数据集(三)
Xiaomi, a young engineer, was just going to make soy sauce
verilog REG 寄存器、向量、整数、实数、时间寄存器
uniapp 使用canvas 生成海报并保存到本地
2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
[staff] restore mark (Introduction to the use of restore mark | example analysis of Metaphone mark and restore mark)
Mongodb base de données non relationnelle
venn圖取交集
PMP personal sprint preparation experience
Verilog 时序控制
Continuous assignment of Verilog procedure
C#联合halcon脱离halcon环境以及各种报错解决经历
高并发场景下缓存处理方案
Jointly developed by nailing, the exclusive functions of glory tablet V7 series were officially launched