当前位置:网站首页>[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)
边栏推荐
- Programmers broke the news: 3 job hopping in 4 years, and the salary has tripled! Netizen: the fist is hard
- acwing 800. Target and of array elements
- 双写一致性问题
- The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.2 低级 I/O(read 和 write)
- calibration of sth
- CAS optimistic lock
- Project training of Shandong University rendering engine system (II)
- Acwing794 high precision Division
- Comprendre le go des modules go. MOD et go. SUM
- Collect | 22 short videos to learn Adobe Illustrator paper graphic editing and typesetting
猜你喜欢
随机推荐
Token and idempotency
ISCC-2022 部分wp
Sha6 of D to large integer
双写一致性问题
std::set compare
<山东大学项目实训>渲染引擎系统(二)
Super detailed dry goods! Docker+pxc+haproxy build a MySQL Cluster with high availability and strong consistency
Anfulai embedded weekly report no. 268: May 30, 2022 to June 5, 2022
Acwing 798 two dimensional difference (difference matrix)
generate pivot data 0
QCustomplot笔记(一)之QCustomplot添加数据以及曲线
How to base on CCS_ V11 new tms320f28035 project
generate pivot data 1
The C Programming Language(第 2 版) 笔记 / 8 UNIX 系统接口 / 8.3 open、creat、close、unlink
PostgreSQL source code (53) plpgsql syntax parsing key processes and function analysis
Browsercontext class of puppeter
h t fad fdads
token与幂等性问题
The C programming language (version 2) notes / 8 UNIX system interface / 8.7 instance (storage allocator)
Analysis of Nacos config dynamic refresh source code







