我是靠谱客的博主 健忘花生,最近开发中收集的这篇文章主要介绍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 join 与where的执行顺序MySQL join 与where的执行顺序所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部