我得到一些奇怪的结果,所以我需要检查自己......
SELECT *
FROM table
WHERE complete != 0
AND pending != 1
要明确,这些是允许的:
pending = 0, complete = 0
pending = 1, complete = 1
pending = 0, complete = 1
不允许从我的查询中返回:
pending = 1, complete = 0
我在这里想念的是什么......?
答案 0 :(得分:37)
尝试:
SELECT *
FROM table
WHERE NOT (complete = 0
AND pending = 1)
或
SELECT *
FROM table
WHERE !(complete = 0
AND pending = 1)
编辑: 我去看了看: http://dev.mysql.com/doc/refman/4.1/en/expressions.html
答案 1 :(得分:9)
您需要使用OR
,而不是AND
。您的表达式会遗漏complete = 0
或pending = 1
的任何组合,这种组合限制性太强。请尝试以下方法:
SELECT *
FROM Table
WHERE complete != 0 OR pending != 1;
^^ change AND to OR