为什么这些查询会返回差异结果:
SELECT *
FROM ProjectStatus PS
WHERE 0 = (SELECT COUNT(*)
FROM Project P
WHERE P.ProjectStatusKey = PS.ProjectStatusKey)
SELECT *
FROM ProjectStatus PS
WHERE PS.ProjectStatusKey NOT IN (SELECT P.ProjectStatusKey
FROM Project P)
答案 0 :(得分:3)
唉。原来它是选项列表中的NULL,打破了整个该死的东西。您必须关闭ANSI NULL或将查询更改为此...
SELECT * FROM ProjectStatus PS WHERE
PS.ProjectStatusKey NOT IN (SELECT P.ProjectStatusKey FROM Project P WHERE P.ProjectStatusKey IS NOT NULL)
答案 1 :(得分:0)
如果您的任何Project.ProjectStatusKey值为NULL,则NOT IN
子句也将计算为NULL,而不是TRUE / FALSE。