今天用到Left join 竟然将语法写错了......
select * from tt left join tt1 on tt.id=tt1.id
id name id name
--------------------------
1 a 1 a
2 b 2 b
3 c 3 c
select * from tt left join tt1 on tt.id=tt1.id where tt.id=1
id name id name
--------------------------
1 a 1 a
select * from tt left join tt1 on tt.id=tt1.id and tt.id=1
id name id name
--------------------------
1 a 1 a
2 b NULL NULL
3 c NULL NULL
--left join 以左边表为基础, 扫描右边表匹配的记录
select * from
table1 left join table2 on 条件1
left join table3 on 条件2
left join table4 on 条件3
where 条件4
本文详细解析了 LEFT JOIN 的使用方法及常见错误,并通过示例对比了不同 WHERE 子句的位置对查询结果的影响。
2113

被折叠的 条评论
为什么被折叠?



