MySQL与条件相反

时间:2016-06-03 12:34:26

标签: mysql sql select logical-operators

我知道在其他语言中,您可以使用某些东西(通常是!)来表示与后续内容相反的内容。有没有办法在MySQL中做这样的事情?

例如,我有这个查询来选择不为空或空白的所有内容:

select * from `invoices` where `Notes`>'';

但有没有办法相反?因为目前我只知道你可以重写这个

这样的查询
select * from `invoices` where ifnull(`Notes`,'')='';

但这样就消除了Notes列上的索引或这种方式的机会

select * from `invoices` where (`Notes` is null or `Notes`=''); 

但那个比

更长的时间
select * from `invoices` where !`Notes`>'';

这将是理想的。

1 个答案:

答案 0 :(得分:1)

SQL有一个not运算符:

SELECT * FROM `invoices` WHERE NOT (`Notes`>'');
-- Here -----------------------^
相关问题