--以下两条语句查询结果一样
select * from t_gasbrand t1 left join t_userfiles t2 on t1.id = t2.f_gasbrand_id where t1.id = 17 --注意这里必须是where不能是and!!!where是取交集而and在left join 语句中并没有效果
select * from t_gasbrand t1,t_userfiles t2 where t1.id = t2.f_gasbrand_id and t1.id = 17
--如果这样写就错误了
select * from t_gasbrand t1 left join t_userfiles t2 on t1.id = t2.f_gasbrand_id and t1.id = 17 --用and连接并不能起到筛选的效果,and在left join 中是无效的,虽然语法上没有报错

在left join 语句中 使用and添加条件无效:


本文探讨了在SQL查询中使用LEFT JOIN时遇到的问题,特别是当尝试在连接条件外使用AND添加额外条件时,这些条件可能无法如预期工作。通过案例分析,解释了为何这种情况会发生以及如何正确构造查询语句。
2307

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



