问题
I am trying to achieve and NOT operation and NAND operation in between Queries.
Scenario 1:
SELECT
country_name,country_code
from country
where not (country_name='Land islands' and country_code='AX');
Works well; Shows all other countries other than the two country which I am mentioning.
Scenario 2:
When I try with some select inside the where condition it shows errors.
SELECT * from
country
where not
(SELECT * from country
where country_name='Land islands'
and
SELECT * from country
where country_code='AX');
It shows an error..
Kindly refer the Link: With my previous question and the working of NOT and NAND operation.
MySQL NAND/NOR operations in Queries
回答1:
AND
should be replaced by UNION
and the primary key
of table (let it assume id
) should be checked with NOT IN
clause.
SELECT * from country
WHERE id NOT IN
(SELECT id from country
where country_name='Land islands'
UNION
SELECT id from country
where country_code='AX'
);
来源:https://stackoverflow.com/questions/16938865/mysql-with-multiple-query-having-nand-opertaion-and-not-operation