我正在使用SQL Server 2008,当我执行一个左外连接到外表没有任何记录的表时,我是从我的where子句看到奇怪的行为。如果我检查我的外表中的值是否为'not null',则有时返回true。SQL:检查'值'不为空当'值'为空时返回TRUE
select *
from foo f left join bar b on b.id=f.id
where [email protected] and (f.status = 1 or b.Price is not null)
当我f.status = 0
和b.Price
不存在(或,出现在选择为空)这个查询选择记录,其中f.status = 0
和b.Price is null
,即使(FALSE或FALSE)应该是假的。
如果我只是执行此查询,它会按预期工作,并且任何没有'bar'中的记录的任何内容都不会被选中。
select *
from foo f left join bar b on b.id=f.id
where [email protected] and b.Price is not null
有b.Price is not null
为or
操作的一部分似乎是造成问题的某些原因。这个查询有什么问题?我使用SQL Server 2012计算机上的类似数据运行相同的查询,但没有看到此问题,它是否与我正在使用的SQL Server版本有关?