假设我有1个表只有多列。让我们说:
Fruits
--------------------------------------
id | name | country
--------------------------------------
1 | Banana | china
2 | Orange | japan
3 | Apple | japan
4 | Apple | china
5 | Banana | usa
6 | Orange | china
然后简单查询SELECT
所有水果id < 6
它是:
SELECT * FROM fruits WHERE id < 6
然后它将返回:
--------------------------------------
id | name | country
--------------------------------------
1 | Banana | china
2 | Orange | japan
3 | Apple | japan
4 | Apple | china
5 | Banana | usa
然后通过附上上述查询,我怎样才能继续排除更多内容 例如:
Do NOT want to see, any "APPLE" from "CHINA".
所以最终结果必须是:
--------------------------------------
id | name | country
--------------------------------------
1 | Banana | china
2 | Orange | japan
3 | Apple | japan
5 | Banana | usa
这又是without
行if, name='Apple' AND country='china'
的行。
我会说:
SELECT * FROM fruits WHERE id < 6 ... AND DON'T RETURN this condition where name='Apple' and country='china' TOGETHER
答案 0 :(得分:2)
尝试:
SELECT *
FROM fruits
WHERE (id < 6)
AND NOT (name = 'Apple' AND country = 'china')
或者:
SELECT *
FROM fruits
WHERE (id < 6)
AND id NOT IN (SELECT id
FROM fruits
WHERE name = 'Apple'
AND country = 'china')
答案 1 :(得分:1)
试试这个
SELECT * FROM fruits WHERE
(name ,country) not in ( select 'Apple' ,'china' from Fruits)
HAVING id < 6