问题描述:
select a.*,b.*
from table1 a
left join table2 b on b.X=a.X
where XXX
如上:一旦使用了left join,没有where条件时,左表table1会显示全部内容
使用了where,只有满足where条件的记录才会显示(左表显示部分或者全部不显示)
so。。。。
left join的困惑:一旦加上where条件,则显示的结果等于inner join
解决方案:
1.
select a.*,tmp.*
from table1 a
left join(
select a.*,b.*
from table1 a
left join table2 b on b.X=a.X
where XXX
)tmp
**2.询条件放在on后面(推荐使用)
select a.*,b.*
from table1 a
left join table2 b on b.X=a.X and XXX**