SQL 'select' 查询有 3 个条件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13552180/
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
SQL 'select' Query with 3 conditions
提问by sanu j
SELECT *
FROM REVIEW
WHERE REVIEWERID =5 AND APPRAISEECONFIRMYN='Y' AND HRCONFIRMYN = NULL
Are 2 'AND' conditions allowed like this? I'm not getting the correct output. There are 2 records in the database that fulfil the above conditions. When I remove the last condition 'HRCONFIRMYN = NULL'
and execute, I get the correct output.
像这样允许 2 个“AND”条件吗?我没有得到正确的输出。数据库中有 2 条记录满足上述条件。当我删除最后一个条件'HRCONFIRMYN = NULL'
并执行时,我得到了正确的输出。
How can this be solved? I need to check all 3 conditions whilst searchng the records.
如何解决这个问题?我需要在搜索记录时检查所有 3 个条件。
回答by Mahmoud Gamal
回答by John Woo
- use
OR
instead - group your condition
- use
IS NULL
when comparing with NULLs
- 使用
OR
替代 - 分组你的条件
- 使用
IS NULL
与空值进行比较时,
query,
询问,
SELECT *
FROM REVIEW
WHERE (REVIEWERID =5 AND APPRAISEECONFIRMYN='Y') OR
HRCONFIRMYN IS NULL