当前位置:网站首页>Mysql internal and external connections
Mysql internal and external connections
2022-07-30 00:05:00 【GSX_MI】
1. Inner join
- Inner joins actually usewhereThe clause filters the Cartesian product formed by the two tables, weThe queries learned earlier are all inner joins, and they are also the most used join queries in the development process.
- Syntax:
select fields from table 1 inner join table 2 on join conditions and other conditions;
- Case: Display SMITH's name and department name
①Front writing
- Where used here is to find information that satisfies the following conditions in all the results after the Cartesian product is performed before
select ename, dname from EMP, DEPT where EMP.deptno=DEPT.deptno and ename='SMITH';②Standard inner join (recommended, elegant)
select ename , dname from EMP inner join DEPT on EMP.deptno = DEPT.deptno where ename = 'SMITH';
2. Outer join
(1) Left outer join
- If the joint query, the table on the left is completely displayed, we say it is a left outer join.
- Take the information in the left table and go to the right table to filter, and all that are satisfied will be displayed, even if there are multiple
select field name from table name 1 left join table name 2 on join condition;
Case: Query the grades of all students, if the student has no grades, also display the student's personal information
- When the left table and the right table do not match, the data of the left table will also be displayedspan>


(2) Right outer join
- If the joint query, the table on the right is completely displayed, we say it is a right outer join.
select field from table name 1 right join table name 2 on join condition;
Case: Jointly query the stu table and the exam table, and display all the grades, even if there is no student corresponding to this grade, it should be displayed

(3)Exercise : List department names and employee information in these departments, and list departments without employees

3. Summary
- When querying, there is a high probability that multiple tables will be involved, and it is often necessary to "merge" multiple tables into one table. The essence of all queries is to convert them into one table query!!
- Self-join, from (sub-query), and internal and external joins are essentially answers to how to complete the merging of multiple tables!!
- Inner join: keep the common connection conditions, left outer join: keep all the information of the left table, right outer join: keep all the information of the right table.
边栏推荐
- 自媒体人如何打造出爆文?这3种类型的文章最容易爆
- 重庆OI 2005 新年好
- 【云原生Kubernetes】二进制搭建Kubernetes集群(中)——部署node节点
- 2022/7/29 Exam Summary
- 新闻文本分类
- vim相关介绍(三)
- Override and customize dependent native Bean methods
- Reading notes. This is the psychology: see through the essence of the pseudo psychology (version 10)"
- 环形链表(LeetCode 141、142)
- mysql使用on duplicate key update批量更新数据
猜你喜欢
随机推荐
窗口函数笔记
【集训DAY18】有趣的交换【模拟】【数学】
Sentinel入门
每周推荐短视频:研发效能是什么?它可以实现反“内卷”?
logback过期日志文件自动删除
NumPy(一)
【集训DAY16】KC ‘ s Stars【dfs】
关于 byte 的范围
单片机开发之基本并行I/O口
EA & UML Sun Gong Yip - Multitasking Programming Super Introductory - (7) About mutex, you must know
ZLMediaKit源码分析 - WebRtc连接迁移
ApplicationContext的三大实现
重庆OI 2005 新年好
【云原生Kubernetes】二进制搭建Kubernetes集群(中)——部署node节点
Adaptive feature fusion pyramid network for multi-classes agriculturalpest detection
C陷阱与缺陷 第5章 库函数 5.1 返回整数的getchar函数
The difference and usage of call, apply and bind
『牛客|每日一题』走迷宫
C陷阱与缺陷 第5章 库函数 5.4 使用errno检测错误
YoloV5数据集自动划分训练集、验证集、测试集









