MySQL WHERE:如何写“!=”或“不等于”?


95

我需要这样做

DELETE FROM konta WHERE taken != ''

但是!=在mysql中不存在。有人知道怎么做吗?

Answers:



38

!=操作肯定是存在的!它是标准<>运算符的别名。

也许您的字段实际上不是空字符串,而是NULL

要进行比较,NULL可以使用IS NULLIS NOT NULLnull安全等于运算符<=>


嗯,我能看到的NULL是怎么回事(+1),但似乎奇怪,想删除不为空或NULL ..

11

您可能正在使用旧版本的Mysql,但可以肯定地使用

 DELETE FROM konta WHERE taken <> ''

但是还有许多其他选择。您可以尝试以下方法

DELETE * from konta WHERE strcmp(taken, '') <> 0;

DELETE * from konta where NOT (taken = '');
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.