0

Lets say i have 1 Table only with multiple columns. Lets say:

Fruits
--------------------------------------
id  | name        | country
--------------------------------------
1   | Banana      | china
2   | Orange      | japan
3   | Apple       | japan
4   | Apple       | china
5   | Banana      | usa
6   | Orange      | china

Then the simple query to SELECT all Fruits where id < 6.
It is:

SELECT * FROM fruits WHERE id < 6

Then it will return:

--------------------------------------
id  | name        | country
--------------------------------------
1   | Banana      | china
2   | Orange      | japan
3   | Apple       | japan
4   | Apple       | china
5   | Banana      | usa

Then by appending above query, how can i go on to EXCLUDE something more.
For example:

Do NOT want to see, any "APPLE" from "CHINA".

So the final result must be:

--------------------------------------
id  | name        | country
--------------------------------------
1   | Banana      | china
2   | Orange      | japan
3   | Apple       | japan
5   | Banana      | usa

This is again without the row that having if, name='Apple' AND country='china' TOGETHER!.

  • So by continuing the first query, how can i ADD the Additional "AND Condition Pair" to get this result, please?

I would say:

SELECT * FROM fruits WHERE id < 6 ... AND DON'T RETURN this condition where name='Apple' and country='china' TOGETHER

2 Answers 2

2

Try:

SELECT * 
FROM fruits 
WHERE (id < 6)
AND NOT (name = 'Apple' AND country = 'china')

Or:

SELECT * 
FROM fruits 
WHERE (id < 6)
AND id NOT IN (SELECT id 
               FROM fruits
               WHERE name = 'Apple'
               AND country = 'china')
Sign up to request clarification or add additional context in comments.

Comments

1

try this

 SELECT * FROM fruits WHERE 
                 (name ,country) not in ( select 'Apple' ,'china' from Fruits)

 HAVING id < 6

DEMO HERE

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.