当前位置:网站首页>There are three kinds of SQL connections: internal connection, external connection and cross connection
There are three kinds of SQL connections: internal connection, external connection and cross connection
2022-07-05 06:18:00 【Ostrich5yw】
SQL Three connections : Internal connection 、 External connection 、 Cross connect
Prepare two sheets and PersonId Related to .
One 、 Cross connect (CROSS JOIN)
Cross connect returns the Cartesian product of all data rows of the connected two tables .
// These two sentences sql Completely equivalent
select * from person CROSS JOIN address
select * from person, address
Query results :
Two 、 Internal connection (INNER JOIN)
The internal connection can obtain the records of the common part of the two tables , That is to use conditional expressions to eliminate some data rows of cross connection .
// These two sentences sql Completely equivalent
select * from person INNER JOIN address ON person.PersonId = address.PersonId
select * from person, address WHERE person.PersonId = address.PersonId
Query results : Notice here PersonId = 4 My little grandson didn't export
Therefore, the inner connection only queries the data contained in both tables
3、 ... and 、 External connection (LEFT JOIN、RIGHT JOIN、FULL JOIN)
Be careful : When connecting outside , Attention should be paid to where And on The difference between
- on The condition is the condition used to generate the temporary table , It doesn't care on Is the condition in true , Will return to the records in the table on the left .
- where The condition is that after the temporary table is generated , Then filter the temporary table . There is no such thing as left join The meaning of ( You have to go back to the records in the table on the left ) 了 , If the conditions are not true, filter them out
1. The left outer join
The result set of the left out join includes all rows of the specified left table , Not just the rows that the join columns match . If a row in the left table does not match a row in the right table , All selection list columns in the right table in the associated result set row are null (null)
select * from person LEFT JOIN address ON person.PersonId = address.PersonId
Query results : Notice here PersonId = 4 Of ‘ Little grandson ’ Also output and due to ‘ Little grandson ’ There is no corresponding address, therefore address Data set to null
2. Right connection
The right outer join is the reverse join of the left outer join . All rows of the right table will be returned . If a row in the right table does not match a row in the left table , Null value will be returned for the left table (null)
select * from person RIGHT JOIN address ON person.PersonId = address.PersonId
Query results : Notice here AddressId = 6 Of ‘ guangdong ’ Also output and due to ‘ guangdong ’ There is no corresponding person, therefore preson Data set to null
3. Complete external connection
Full outer join returns all rows in the left and right tables . When a row has no matching row in another table , The selection list column of another table contains null values (null)Mysql China does not support it. FULL JOIN, So here we use UNION Joint query instead of
select * from person LEFT JOIN address ON person.PersonId = address.PersonId
UNION
select * from person RIGHT JOIN address ON person.PersonId = address.PersonId
Query results : At the same time, it outputs ' Little grandson ' as well as ' guangdong '
边栏推荐
- 1.14 - assembly line
- Filter the numbers and pick out even numbers from several numbers
- Sword finger offer II 058: schedule
- 数据可视化图表总结(二)
- Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
- NotImplementedError: Cannot convert a symbolic Tensor (yolo_boxes_0/meshgrid/Size_1:0) to a numpy ar
- Single chip computer engineering experience - layered idea
- 可变电阻器概述——结构、工作和不同应用
- LVS简介【暂未完成(半成品)】
- 【Rust 笔记】15-字符串与文本(上)
猜你喜欢
1.15 - input and output system
Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
Introduction to LVS [unfinished (semi-finished products)]
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
MySQL advanced part 2: optimizing SQL steps
数据可视化图表总结(一)
Appium automation test foundation - Summary of appium test environment construction
Data visualization chart summary (I)
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis
1.13 - RISC/CISC
随机推荐
Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
MySQL advanced part 2: SQL optimization
Introduction to LVS [unfinished (semi-finished products)]
C - XOR to all (binary topic)
Overview of variable resistors - structure, operation and different applications
可变电阻器概述——结构、工作和不同应用
Open source storage is so popular, why do we insist on self-development?
博弈论 AcWing 893. 集合-Nim游戏
开源存储这么香,为何我们还要坚持自研?
1039 Course List for Student
QQ电脑版取消转义符输入表情
C Primer Plus Chapter 15 (bit operation)
[BMZCTF-pwn] ectf-2014 seddit
RGB LED infinite mirror controlled by Arduino
SQL三种连接:内连接、外连接、交叉连接
Daily question 1189 Maximum number of "balloons"
[leetcode] day94 reshape matrix
【LeetCode】Easy | 20. Valid parentheses
The difference between CPU core and logical processor
[rust notes] 13 iterator (Part 2)