MySQL WHERE:如何写“!=”或“不等于”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11421741/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
MySQL WHERE: how to write "!=" or "not equals"?
提问by Posttwo
I need to do this
我需要这样做
DELETE FROM konta WHERE taken != ''
But != doesn't exist in mysql. Anyone know how to do this?
但是 != 在 mysql 中不存在。有人知道怎么做吗?
回答by RolandoMySQLDBA
DELETE FROM konta WHERE taken <> '';
回答by Mark Byers
The != operatormost certainly does exist! It is an alias for the standard <>
operator.
该!=操作肯定是存在的!它是标准<>
运算符的别名。
Perhaps your fields are not actually empty strings, but instead NULL
?
也许您的字段实际上不是空字符串,而是NULL
?
To compare to NULL
you can use IS NULL
or IS NOT NULL
or the null safe equals operator <=>
.
为了与NULL
您进行比较,您可以使用IS NULL
或IS NOT NULL
或空安全等于运算符<=>
。
回答by minhas23
You may be using old version of Mysql but surely you can use
您可能使用的是旧版本的 Mysql,但您肯定可以使用
DELETE FROM konta WHERE taken <> ''
But there are many other options available. You can try the following ones
但是还有许多其他选项可用。你可以试试下面的
DELETE * from konta WHERE strcmp(taken, '') <> 0;
DELETE * from konta where NOT (taken = '');