当前位置:网站首页>Mysql A left(right) join B on A.id=B. ID and a.age=1 and a left (right) join b on a.id=b id where A.age=1
Mysql A left(right) join B on A.id=B. ID and a.age=1 and a left (right) join b on a.id=b id where A.age=1
2022-07-23 07:57:00 【"@ book mountain has a path%"】
Mysql Of join…on…and… And join…on…where… The difference between
Mysql A left(right) join B on A.id=B.id and A.age=1 And A left(right) join B on A.id=B.id where A.age=1 The difference between
Table building and data preparation
Create left and right tables , And table building statements and data insertion
create table tab_left(
id int,
name int,
age int,
sex int
);
insert into tab_left values(1,1,1,1),(2,2,2,2),(3,3,3,3),(4,4,4,4),(5,5,5,5),(6,6,6,6);
create table tab_right(
id int,
state int,
money int
);
insert into tab_right values(1,1,1),(2,2,2),(3,3,3),(4,4,4),(7,7,7),(8,8,8);
see tab_left data
select * from tab_left;

See the table tab_right data
select * from tab_right;

Internal connection
There is no difference between the two
adopt id Make internal connections , And specify the left table name Equal to a specific value , Can only get name Records equal to a specific value .
select * from tab_left l join tab_right r on l.id=r.id where l.name=2;
select * from tab_left l join tab_right r on l.id=r.id and l.name=2;
Consistent result 
select * from tab_left l join tab_right r on l.id=r.id and r.state=8;
After internal connection ,8 It doesn't contain ,where Filter no records , So for null
Left connection ( The right connection is similar )
join...on....and... Connect on the left ( The right connection ) eligible Make internal connections , Do not conform to the Make external connections
join...on...where..., Connect outside first , It's filtering
where 1
select * from tab_left l left join tab_right r on l.id=r.id where l.name=2;
Through the first id Make external connections , Re filtration name Records equal to a specific value .
and 1
select * from tab_left l left join tab_right r on l.id=r.id and l.name=2;
If only the left connection is made ,1 To 4 Internal connection should be made ,5 To 6 Make external connections ,
add name The connection condition is amount to Only the qualified ones are internally connected , Others use external connections . Only 2 accord with , Make internal connections 
where 2
select * from tab_left l left join tab_right r on l.id=r.id where r.state=3;
Through the first id Make external connections , Re filtration state Records equal to a specific value .
and 2
select * from tab_left l left join tab_right r on l.id=r.id and r.state=3;
If only the left connection is made ,1 To 4 Internal connection should be made ,5 To 6 Make external connections ,
add state The connection condition is amount to Only the qualified ones are internally connected , Others use external connections . Only 3 accord with , Make internal connections 
and 3
select * from tab_left l left join tab_right r on l.id=r.id and r.state=8;
If only the left connection is made ,1 To 4 Internal connection should be made ,5 To 6 Make external connections ,
add state The connection condition is amount to Only the qualified ones are internally connected , Others use external connections . There is no such thing as , So all on the right are null.
边栏推荐
- ASP.Net Core创建MVC项目上传多个文件(流方式)
- Scala when used Performance problems of contains().Exists()
- Scala gets all files in the specified directory
- flink批量读取es
- Scala main constructor_ Scala main constructor depth
- Overview of multisensor fusion -- FOV and bev
- 百度搜索打击盗版网文站点:互联网内容侵权现象为何屡禁不止
- 局域网SDN硬核技术内幕 17 从一到百
- Scala generic generic class details - t
- “蔚来杯“2022牛客暑期多校训练营1 (部分题目总结)
猜你喜欢

实验七 H.264文件分析

一次 MySQL 误操作导致的事故,「高可用」都顶不住了

牛客小白月赛53

@Transactional事务方法中包含多个同类事务方法,这些事务方法本身设置失效两种解决方案

VMware 中搭建 SylixOS 环境

程序员最想干的三件事 |漫画

File upload, server file name Chinese garbled file upload, server file name Chinese garbled

2022 employment season surprise! The genuine Adobe software can finally be used for nothing

一文深入浅出理解国产开源木兰许可系列协议

基于ROS的导航框架
随机推荐
基于ROS的导航框架
1.10 API 和字符串
The Chinese and English dot matrix character display principle of the 111th blog of the fledgling Xiao Li
我是如何在一周内拿到4份offer的?
Problems encountered in punching
squid代理服务+ip代理池
文件的一般、特殊、隐藏属性(实例生动画图)
Amazon's zoox passed the safety test and applied for a test drive in California
Fledgling Xiao Li's 108th blog binary print
LAN SDN hard core technology insider 19 unite all forces that can be united
ASP.Net Core创建MVC项目上传多个文件(流方式)
关于Redis,是先更新数据库,还是先更新缓存?
Simulate not all endpoints registered exceptions and Solutions
沃尔沃xc90的安全性如何?一起来看看吧
如何优雅的改变this指向
主题域模型
弥散张量分析开源软件 DSI Studio 简体中文汉化版可以下载了
About redis, do you update the database first or the cache first?
pycharm中使用私钥远程连接服务器
Graduation project ----- Internet of things environment detection system based on stm32