当前位置:网站首页>The difference between SQL left join main table restrictions written after on and where
The difference between SQL left join main table restrictions written after on and where
2022-07-02 11:13:00 【Don't eat swan meat】
As the title , Suppose there is such a sql topic
with a as (
select 1 as id , 'a' as name
union all
select 1,'b'
),
b as (
select 1 as id1, 'q' as name1
union all
select 1 , 'w'
)
select count(*) from (
select *,'a' as num
from a
left join b
on a.id = b.id1
and a.name = 'a'
Ask the answer ?
Presumably most people will answer 2 , At least I am . In my original understanding , This sql The execution sequence of should be like this
- Perform correlation , There are four results , The data is 1 a 1 q; 1 a 1 w; 1 b 1 q; 1 b 1 w;
- filtering , Get rid of a.name <>'a’ Of ,
The final result is 1 a 1 q; 1 a 1 w;
But this is wrong !!!
For this sql Come on , The order of execution should be like this .
- First detected left join , Go straight back to a Table all results , The result is 1 a ;1 b
- take a Table compliance a.name = 'a’ Of , To be with b Tables are associated , Do not meet the conditions ,b Table set as null, The result is 1 a 1 q; 1 a 1 w; 1 b null null
therefore , The result is 3
Make a note of , To sum up your experience
边栏推荐
- JSP webshell free -- the basis of JSP
- TIPC Cluster5
- [AI application] Hikvision ivms-4200 software installation
- How does the whole network display IP ownership?
- JVM garbage collector
- Jenkins安装
- js中给数组添加元素的方法有哪些
- 二叉树专题--AcWing 47. 二叉树中和为某一值的路径(前序遍历)
- 使用华为性能管理服务,按需配置采样率
- V2x SIM dataset (Shanghai Jiaotong University & New York University)
猜你喜欢

enumrate的start属性的坑

【深入浅出玩转FPGA学习3-----基本语法】
![[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?](/img/66/674a06d8e45a31ae879b81554ef373.png)
[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?

Special topic of binary tree -- Logu p1229 traversal problem (the number of traversals in the middle order is calculated when the pre and post order traversals of the multiplication principle are know
![二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)](/img/c2/bb85b681af0f78b380b1d179c7ea49.png)
二叉树专题--洛谷 P3884 [JLOI2009]二叉树问题(dfs求二叉树深度 bfs求二叉树宽度 dijkstra求最短路)

Use of vscode tool

二叉树专题--AcWing 18. 重建二叉树(利用前、中序遍历,构建二叉树)

二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)
![[in simple terms, play with FPGA learning 3 ----- basic grammar]](/img/f0/0204fa5197033877dc0758203253ae.png)
[in simple terms, play with FPGA learning 3 ----- basic grammar]

实验电镜距离测量之Matlab处理
随机推荐
【AI应用】海康威视iVMS-4200软件安装
Complement (Mathematical Simulation
主键策略问题
Openmldb meetup No.4 meeting minutes
STM32单片机编程学习
实验电镜距离测量之Matlab处理
PCL point cloud to depth image
Use Huawei performance management service to configure the sampling rate on demand
【深入浅出玩转FPGA学习3-----基本语法】
Luogu p4281 [ahoi2008] emergency gathering / gathering (tree doubling LCA)
How to use ide to automatically sign and debug Hongmeng application
TIPC introduction 1
I STM32 development environment, keil5/mdk5.14 installation tutorial (with download link)
OpenMLDB Meetup No.4 会议纪要
Hdu1228 a + B (map mapping)
C# 文件与文件夹操作
Special topic of binary tree -- acwing 18 Rebuild the binary tree (construct the binary tree by traversing the front and middle order)
TIPC messaging3
Internship report skywalking distributed link tracking?
QT学习日记8——资源文件添加