SQL WHERE条件不等于? [英] SQL WHERE condition is not equal to?
本文介绍了SQL WHERE条件不等于?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以否定where子句?
Is it possible to negate a where clause?
例如
DELETE * FROM table WHERE id != 2;
推荐答案
您可以这样做
DELETE FROM table WHERE id NOT IN ( 2 )
或
DELETE FROM table WHERE id <> 2
正如@Frank Schmitt指出的那样,您可能还需要注意NULL值.如果要删除不是2
的所有内容(包括NULL),请在WHERE子句中添加OR id IS NULL
.
As @Frank Schmitt noted, you might want to be careful about the NULL values too. If you want to delete everything which is not 2
(including the NULLs) then add OR id IS NULL
to the WHERE clause.
这篇关于SQL WHERE条件不等于?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文