当前位置:网站首页>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
边栏推荐
- Luogu p1892 [boi2003] Gang (and search for variant anti set)
- [play with FPGA learning 2 in simple terms ----- design skills (basic grammar)]
- php中self和static在方法中的区别
- Uncover the secrets of Huawei application market application statistics
- sql left join 主表限制条件写在on后面和写在where后面的区别
- TIPC介绍1
- mmrotate旋转目标检测框架使用记录
- 函数式接口和方法引用
- Special topic of binary tree -- acwing 1589 Building binary search tree
- [applinking practical case] share in app pictures through applinking
猜你喜欢

华为快应用中如何实现同时传递事件对象和自定义参数

ImportError: cannot import name ‘Digraph‘ from ‘graphviz‘

Common methods of JS array

flink二开,实现了个 batch lookup join(附源码)

二叉树专题--AcWing 3384. 二叉树遍历(已知先序遍历 边建树 边输出中序遍历)

QT learning diary 7 - qmainwindow

From Read and save in bag file Jpg pictures and PCD point cloud

JVM garbage collector

The first white paper on agile practice in Chinese enterprises was released | complete download is attached

Why does LabVIEW lose precision in floating point numbers
随机推荐
Special topic of binary tree -- acwing 3384 Binary tree traversal (known preorder traversal, while building a tree, while outputting middle order traversal)
PCL extracts a subset from a point cloud
From the perspective of attack surface, see the practice of zero trust scheme of Xinchuang
String (Analog
函数式接口和方法引用
TIPC Cluster5
Logu p3398 hamster looks for sugar (double LCA on the tree to judge whether the two paths in the tree intersect)
Verilog 和VHDL有符号数和无符号数相关运算
三.芯片启动和时钟系统
[play with FPGA learning 5 in simple terms ----- reset design]
【深入浅出玩转FPGA学习3-----基本语法】
二叉树专题--洛谷 P1229 遍历问题(乘法原理 已知前、后序遍历求中序遍历个数)
二叉树专题--AcWing 3384. 二叉树遍历(已知先序遍历 边建树 边输出中序遍历)
华为AppLinking中统一链接的创建和使用
From Read and save in bag file Jpg pictures and PCD point cloud
TIPC Service and Topology Tracking4
TIPC Service and Topology Tracking4
洛谷 P1892 [BOI2003]团伙(并查集变种 反集)
二叉树专题--AcWing 3540. 二叉搜索树建树(实用板子 构建二叉搜索树 并输出前、中、后序遍历)
实验电镜距离测量之Matlab处理