where b.col1 is null
先左联接再筛选掉b.col1 为空的记录,返回table1有但table2没有的记录。on a.col1=b.col1 and b.col1 is null
在左联接的时候判断,当b.col1都不空时,返回table1的所有记录。
先左联接再筛选掉b.col1 为空的记录,返回table1有但table2没有的记录。on a.col1=b.col1 and b.col1 is null
在左联接的时候判断,当b.col1都不空时,返回table1的所有记录。
from table1 a left join table2 b
on a.col1=b.col1
where b.col1 is null分两步,先left join 条件是 a.col1=b.col1,再筛选,条件是where b.col1 is null
left join的结果是条件 a.col1=b.col1成立的所有组合+table1有table2没有的记录
筛选把条件 a.col1=b.col1成立的所有组合筛选掉了,
结果剩下table1有table2没有的记录select a.col1,a.col2,b.col1,b.col2
from table1 a left join table2 b
on a.col1=b.col1
and b.col1 is null只有一步,left join 条件是 a.col1=b.col1 and b.col1 is null
因为如果a.col1=b.col1成立,那b.col1 is null一定不成立,所以没有匹配,就只有
table1的所有记录,table的字段全是null了