我是靠谱客的博主 健忘花生,这篇文章主要介绍MySQL join 与where的执行顺序MySQL join 与where的执行顺序,现在分享给大家,希望可以做个参考。

MySQL join 与where的执行顺序

-- 写法ok 先过滤后join
select * from(select * from u1 where u1.id=3)t join u2  on t.id=u2.id;
id  name id(1) sex
3	c	3	male

-- 写法ok 先join后过滤
select * from u1 join u2 on u1.id=u2.id where u1.id=3;
id  name id(1) sex
3	c	3	male

-- 写法ok
select * from u1 join u2 on u1.id=u2.id and u1.id=3;
id  name id(1) sex
3	c	3	male

-- 此种写法不可以 报错
select * from u1 where u1.id=3 join u2 on u1.id=u2.id;
-- You have an error in your SQL syntax; 
check the manual that corresponds to your MySQL server version for the right syntax to use near 'join u2 on u1.id=u2.id' at line 1

select * from u1 left join u2 on u1.id=u2.id where u1.id=3;
id  name id(1) sex
3	c	3	male

select * from u1 left join u2 on u1.id=u2.id and u1.id=3;
id  name id(1) sex
3	c	3	male
1	a	null null	
2	b	null null

最后

以上就是健忘花生最近收集整理的关于MySQL join 与where的执行顺序MySQL join 与where的执行顺序的全部内容,更多相关MySQL内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(120)

评论列表共有 0 条评论

立即
投稿
返回
顶部