也许是一个愚蠢的问题,但请考虑以下两张表:
T1
Store Year
01 2009
02 2009
03 2009
01 2010
02 2010
03 2010
T2
Store
02
为什么这个 INNER JOIN 给了我想要的结果(过滤 ON 子句中的 [year]):
select t1.*
from t1
inner join t2
on t1.store = t2.store
and t1.[year] = '2009'
Store Year
02 2009
为什么 LEFT OUTER JOIN 包括 2010 年的记录?
select t1.*
from t1
left outer join t2
on t1.store = t2.store
and t1.year = '2009'
where t2.store is null
01 2009
03 2009
01 2010
02 2010
03 2010
而且我必须在“WHERE”子句中编写 [year] 过滤器:
select t1.*
from t1
left outer join t2
on t1.store = t2.store
where t2.store is null
and t1.year = '2009'
01 2009
03 2009
就像我说的,也许是一个愚蠢的问题,但它困扰着我!