Mysql with multiple query having NAND opertaion and NOT operation

折月煮酒 提交于 2019-12-11 18:52:46

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!