当我在没有 where 子句的情况下点击下面的代码时,它显示具有 NULL
值的行但是当我像下面这样放置 where 子句时,没有具有 NULL
值的行。
我希望带有 NULL
值的行带有 where 子句。
SELECT *
FROM project_category as a
LEFT OUTER JOIN project_estimate_detail as b
ON a.id = b.project_cat_id
where b.project_cat_id not in ('21','22','2')
最佳答案
试试这个:
SELECT *
FROM project_category as a
LEFT OUTER JOIN project_estimate_detail as b
ON a.id = b.project_cat_id
where (b.project_cat_id IS NULL) OR (b.project_cat_id not in ('21','22','2'))
当 b.project_cat_id
为 NULL
时,NOT IN
的计算结果为 NULL
。因此,您必须使用 IS NULL
表达式显式检查 NULL
。
关于mysql - 还显示具有 NULL 值的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35547037/