当前位置:网站首页>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 '
边栏推荐
- Sqlmap tutorial (II) practical skills I
- Erreur de connexion Navicat à la base de données Oracle Ora - 28547 ou Ora - 03135
- 背包问题 AcWing 9. 分组背包问题
- [leetcode] day95 effective Sudoku & matrix zeroing
- leetcode-6109:知道秘密的人数
- MIT-6874-Deep Learning in the Life Sciences Week 7
- 可变电阻器概述——结构、工作和不同应用
- Redis publish subscribe command line implementation
- Spark中groupByKey() 和 reduceByKey() 和combineByKey()
- Traversal of leetcode tree
猜你喜欢

1.14 - assembly line
![[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis](/img/20/826cc9d514496955a557439881234d.jpg)
[2020]GRAF: Generative Radiance Fields for 3D-Aware Image Synthesis

MySQL advanced part 2: MySQL architecture

Spark中groupByKey() 和 reduceByKey() 和combineByKey()

Sqlmap tutorial (II) practical skills I

SPI details

MySQL advanced part 1: index

Leetcode-6110: number of incremental paths in the grid graph

Sqlmap tutorial (1)

博弈论 AcWing 893. 集合-Nim游戏
随机推荐
Flutter Web 硬件键盘监听
阿里新成员「瓴羊」正式亮相,由阿里副总裁朋新宇带队,集结多个核心部门技术团队
对for(var i = 0;i < 5;i++) {setTimeout(() => console.log(i),1000)}的深入分析
Arduino 控制的 RGB LED 无限镜
leetcode-1200:最小绝对差
【Rust 笔记】17-并发(上)
redis发布订阅命令行实现
A reason that is easy to be ignored when the printer is offline
Usage scenarios of golang context
Data visualization chart summary (II)
JS quickly converts JSON data into URL parameters
Error ora-28547 or ora-03135 when Navicat connects to Oracle Database
MySQL advanced part 2: storage engine
1.14 - assembly line
1041 Be Unique
Leetcode heap correlation
Filter the numbers and pick out even numbers from several numbers
Appium foundation - use the first demo of appium
Navicat连接Oracle数据库报错ORA-28547或ORA-03135
[BMZCTF-pwn] ectf-2014 seddit