当前位置:网站首页>[MySQL] internal connection, external connection and self connection (detailed explanation)
[MySQL] internal connection, external connection and self connection (detailed explanation)
2022-06-12 16:39:00 【zbossz】
First , Internal connection available surface 1 join surface 2on Conditions or surface 1 Alias 1 join surface 2 Alias 2 on Conditions It can also be used. from surface 1, surface 2
Let's start by creating 2 A watch :

Then let's understand the inner connection , External connection :

Here is the inner connection
mysql> select student.name,class.className from student join class on student.classId = class.classId;
+------+-----------+
| name | className |
+------+-----------+
| z1 | c1 |
| z2 | c2 |
| z3 | c3 |
+------+-----------+
3 rows in set (0.00 sec)
mysql> select stu.name,cla.className from student stu join class cla on stu.classId = cla.classId;
+------+-----------+
| name | className |
+------+-----------+
| z1 | c1 |
| z2 | c2 |
| z3 | c3 |
+------+-----------+
3 rows in set (0.00 sec)
Below is the left outer connection
mysql> select student.name,class.className from student left join class on student.classId = class.classId;
+------+-----------+
| name | className |
+------+-----------+
| z1 | c1 |
| z2 | c2 |
| z3 | c3 |
| z4 | NULL |
| z5 | NULL |
+------+-----------+
5 rows in set (0.00 sec)
mysql> select stu.name,cla.className from student stu left join class cla on stu.classId = cla.classId;
+------+-----------+
| name | className |
+------+-----------+
| z1 | c1 |
| z2 | c2 |
| z3 | c3 |
| z4 | NULL |
| z5 | NULL |
+------+-----------+
5 rows in set (0.00 sec)
The following is the right outer connection
mysql> select student.name,class.className from student right join class on student.classId = class.classId;
+------+-----------+
| name | className |
+------+-----------+
| z1 | c1 |
| z2 | c2 |
| z3 | c3 |
| NULL | c99 |
| NULL | c88 |
+------+-----------+
5 rows in set (0.00 sec)
mysql> select stu.name,cla.className from student stu right join class cla on stu.classId = cla.classId;
+------+-----------+
| name | className |
+------+-----------+
| z1 | c1 |
| z2 | c2 |
| z3 | c3 |
| NULL | c99 |
| NULL | c88 |
+------+-----------+
5 rows in set (0.00 sec)
Next, let's look at self connection , The self connected table is itself , That is, self and self combination :
Let's create a table :
mysql> select * from studentscore as ss1,studentscore as ss2
-> where ss1.studentId = ss2.studentId
-> and ss1.courseId = 1
-> and ss2.courseId = 3
-> and ss1.score< ss2.score;
+-----------+-------------+----------+------------+-------+-----------+-------------+----------+------------+-------+
| studentId | studentName | courseId | courseName | score | studentId | studentName | courseId | courseName | score |
+-----------+-------------+----------+------------+-------+-----------+-------------+----------+------------+-------+
| 3 | z3 | 1 | chinese | 45 | 3 | z3 | 3 | english | 89 |
+-----------+-------------+----------+------------+-------+-----------+-------------+----------+------------+-------+
1 row in set (0.00 sec)
边栏推荐
- How to base on CCS_ V11 new tms320f28035 project
- The C programming language (version 2) notes / 8 UNIX system interface / 8.2 low level i/o (read and write)
- The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.1 文件描述符
- pbootcms的if判断失效直接显示标签怎么回事?
- Comprendre le go des modules go. MOD et go. SUM
- 使用 .NET 升级助手将NET Core 3.1项目升级为.NET 6
- acwing 802. Interval sum (discretization)
- acwing 790. The cubic root of a number (floating-point number in half)
- <山东大学项目实训>渲染引擎系统(六)
- <山东大学项目实训>渲染引擎系统(八-完)
猜你喜欢

Super detailed dry goods! Docker+pxc+haproxy build a MySQL Cluster with high availability and strong consistency

Leetcode 2194. Excel 錶中某個範圍內的單元格(可以,已解决)

Overview of webrtc's audio network Countermeasures

Large scale real-time quantile calculation -- a brief history of quantitative sketches

超详细干货!Docker+PXC+Haproxy搭建高可用强一致性的MySQL集群

Leetcode 2194. Cells within a range in Excel table (yes, solved)

Cookie 和 Session

IDEA在控制台显示出services,统一管理所有的jetty服务,

MySQL interview arrangement

Batch --03---cmdutil
随机推荐
大规模实时分位数计算——Quantile Sketches 简史
MySQL - server configuration related problems
pbootcms的if判断失效直接显示标签怎么回事?
Acwing 1927 automatic completion (knowledge points: hash, bisection, sorting)
Thinking about the probability of drawing cards in the duel link of game king
《安富莱嵌入式周报》第268期:2022.05.30--2022.06.05
\begin{algorithm} 笔记
generate pivot data 0
h t fad fdads
关于组件传值
Why is your next computer a computer? Explore different remote operations
About component value transfer
1.delete
Page class of puppeter
Statistical machine learning code set
vim 从嫌弃到依赖(16)——宏
CAS optimistic lock
Collect | 22 short videos to learn Adobe Illustrator paper graphic editing and typesetting
<山东大学项目实训>渲染引擎系统(二)
Understand go modules' go Mod and go sum