select a.* from a 
left outer join b on a.id = b.aid
left outer join c on a.id = c.cid 
-- and c.code = b.code 

-- where c.code=b.code 

其中 c.code=b.code 在left join的时候回保留a中的空值

但是放到where中 c或者是d的code在left join后会被过滤掉。

当你想保留 b中存在,但是b和c在连接的时候c中为空的值,选择on

当你想过滤掉c中的空值选择where 。

数排查方法:

select a.*

,b.code as bcode

,c.code as ccode 

from a 

left outer join b on a.id = b.aid
left outer join c on a.id = c.cid 
-- and c.code = b.code 

-- where c.code=b.code 

查看 主表的主键,bcode,ccode 两列值。

这是一复杂问题的简单描述,有具体应用的情况,配合数据核查,才能深入理解on和where的区别。

别说我是怎么知道的,我不会告诉你我是查数据并结合业务才理解清楚的。