原来预想是会查找出两张表所有的符合on条件数据,也没有经过测试,结果出现线上问题了
-- 原始SQL
select * from A AS T1 full join (select * from B where B条件)T2 on T1.id = T2.id where A条件
原因出在where 的A条件会对连接之后的临时表数据进行筛选,把临时表中符合B条件但不满足ON连接条件的数据(A表中字段为Null)也给筛选掉了。
连接后的临时表示意图如下:
-- 正确sql
select * from( ( select * from A WHERE A条件)t1 full join (select * from B where B条件)T2 on t1.id = t2.id )