left join不显示空值

时间:2013-06-21 00:29:33

标签: sql-server null left-join

我需要找到表A中存在但不存在于表B中的项目。现在,在MySQL中执行这样的连接非常简单

select * from A 
left join B on A.key=B.key 
where B.key is null

但由于某些原因,这在MSSQL中无效。我创建了没有where子句的查询来查看所有结果,我只看到匹配,而不是空值。你知道为什么这不起作用吗?

我知道我可以选择“当不存在时”,但我想知道为什么连接不起作用的原因。

我正在为您的评论添加代码

select Absences.CustomerID, b.* 
from (
    select * from openquery(JUAN_INTERFACE,'select cmp_wwn from Planet_Customers where   i_outcome =4')) b 
left join Absences on Absences.CustomerID = b.cmp_wwn 
where Absences.Type = 3223

1 个答案:

答案 0 :(得分:0)

您的where子句正在过滤掉空值:

where Absences.Type = 3223

您从openquery子查询到Absences左转;然后只过滤Absences列中具有特定(非空)值的行。

你的意思是从Absensesopenquery加入其他方式吗?

相关问题