SQL db2 查询条件 where column not in () 而 column value is null

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27816596/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 03:08:11  来源:igfitidea点击:

db2 query condition where column not in () while the column value is null

sqlnulldb2where-in

提问by Panadol Chong

Good day,

再会,

I have a row of data with a column, call status, the value inside is null.

我有一行数据,一列,调用状态,里面的值为空。

If I query select * from table where status not in ('EXP'), before I run this query, I thought I can select the row of data because status=null, consider not in ('EXP')also. After I tried, I found that I cant query out this row of data. Wish to know why this happen.

如果我查询select * from table where status not in ('EXP'),在我运行这个查询之前,我想我可以选择数据行,因为status=nullnot in ('EXP')也考虑一下。试了下,发现这行数据查询不出来。想知道为什么会这样。

Try to Google it but maybe my question is not correct so I cant get correct search result from Google.

尝试谷歌它,但也许我的问题不正确,所以我无法从谷歌获得正确的搜索结果。

Kindly advise.

好心提醒。

回答by

NULL values are only checked with IS NULLor IS NOT NULL

NULL 值仅使用IS NULL或检查IS NOT NULL

SELECT * 
  FROM table 
 WHERE status NOT IN ('EXP')
    OR status IS NULL;

Hope I have understand your question.

希望我明白你的问题。

Maybe the other way around

也许反过来

SELECT * 
  FROM table 
 WHERE status NOT IN ('EXP')
   AND status IS NOT NULL;