当前位置:网站首页>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
边栏推荐
- Leetcode 182 Find duplicate email (2022.07.01)
- 二叉树专题--AcWing 18. 重建二叉树(利用前、中序遍历,构建二叉树)
- Tick Data and Resampling
- 洛谷 P3398 仓鼠找 sugar(树上倍增 lca 判断树中两条路径是否相交 结论)
- Multi line display and single line display of tqdm
- Primary key policy problem
- TIPC messaging3
- Use of vscode tool
- 【深入浅出玩转FPGA学习3-----基本语法】
- 二叉树专题--AcWing 1589. 构建二叉搜索树
猜你喜欢
随机推荐
如何使用IDE自动签名调试鸿蒙应用
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
TIPC协议
Multi line display and single line display of tqdm
From Read and save in bag file Jpg pictures and PCD point cloud
[AGC] build service 3 - authentication service example
The most detailed MySQL installation tutorial
Mongodb learning and sorting (condition operator, $type operator, limit() method, skip() method and sort() method)
Tick Data and Resampling
ctf 记录
Special topic of binary tree -- acwing 3540 Binary search tree building (use the board to build a binary search tree and output the pre -, middle -, and post sequence traversal)
金山云——2023届暑期实习
MTK full dump抓取
【深入浅出玩转FPGA学习3-----基本语法】
Appgallery connect scenario development practice - image storage and sharing
TIPC messaging3
Why does LabVIEW lose precision in floating point numbers
Supermarket (heap overload
三.芯片启动和时钟系统
从攻击面视角,看信创零信任方案实践









