当前位置:网站首页>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
边栏推荐
- tqdm的多行显示与单行显示
- QT learning diary 8 - resource file addition
- Appgallery connect scenario development practice - image storage and sharing
- Special topic of binary tree -- acwing 19 The next node of the binary tree (find the successor of the node in the tree)
- TIPC Getting Started6
- ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘
- 二叉树专题--P1030 [NOIP2001 普及组] 求先序排列
- TIPC addressing 2
- ctf 记录
- [play with FPGA learning 5 in simple terms ----- reset design]
猜你喜欢
[AGC] how to solve the problem that the local display of event analysis data is inconsistent with that in AGC panel?
QT learning diary 8 - resource file addition
华为应用市场应用统计数据问题大揭秘
TIPC messaging3
TIPC messaging3
Win11 arm system configuration Net core environment variable
三.芯片启动和时钟系统
PKG package manager usage instance in FreeBSD
如何用list组件实现tabbar标题栏
[AI application] Hikvision ivms-4200 software installation
随机推荐
Calculate the sum of sequences
Special topic of binary tree -- acwing 1497 Traversal of the tree (use post and mid order traversal to build a binary tree)
JSP webshell free -- the basis of JSP
static 函数中的静态变量
How to implement tabbar title bar with list component
LVM操作
洛谷 P1892 [BOI2003]团伙(并查集变种 反集)
How to use ide to automatically sign and debug Hongmeng application
洛谷 P3398 仓鼠找 sugar(树上倍增 lca 判断树中两条路径是否相交 结论)
TIPC messaging3
Array splitting (regular thinking
实验电镜距离测量之Matlab处理
二叉树专题--AcWing 19. 二叉树的下一个节点(找树中节点的后继)
Iii. Système de démarrage et d'horloge à puce
Tick Data and Resampling
Uncover the secrets of Huawei application market application statistics
计算序列之和
Common methods of JS array
Implementation of six singleton modes
华为应用市场应用统计数据问题大揭秘