-- 写法ok 先过滤后joinselect*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
-- 写法okselect*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=3join 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 touse near 'join u2 on u1.id=u2.id' at line 1select*from u1 leftjoin u2 on u1.id=u2.id where u1.id=3;
id name id(1) sex
3 c 3 male
select*from u1 leftjoin u2 on u1.id=u2.id and u1.id=3;
id name id(1) sex
3 c 3 male
1 a nullnull2 b nullnull
MySQL join 与where的执行顺序-- 写法ok 先过滤后joinselect * from(select * from u1 where u1.id=3)t join u2 on t.id=u2.id;id name id(1) sex3 c 3 male-- 写法ok 先join后过滤select * from u1 join u2 on u1.id=u2.id where u1.id=3;id name id(1) sex3 c 3 male-- 写法oksel