我正在尝试从 MySQL 中的问题表中获取一些行,如下所示:
SELECT *
FROM raise_question
where documentID = '1'
and delReq != 1 OR delReq IS NULL
但是,某些行具有不同的 documentID
。 (请看图片)。这是返回我想要的结果的正确方法(使用 HAVING
而不是 AND
)(它只包含特定的 documentID
):
SELECT *
FROM raise_question
where documentID = '1'
having delReq != 1 OR delReq IS NULL
最佳答案
您的WHERE
翻译为
where (documentID = '1'
and delReq != 1) OR delReq IS NULL
,因为 AND
的优先级高于 OR
将括号放入 OR
语句中。
where documentID = '1'
and (delReq <> 1 OR delReq IS NULL)
关于MySQL使用where & 和条件过滤结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57825362/