MySQL 的 not 和 not equal 运算符失败,是什么原因造成的?
我有一个表 T,其中有一列 A。A 以默认值 NULL 开头。 40 行后,我将默认值更改为 1。三行的值为 2。我尝试选择 A 列不是 2 的所有行,并将它们设置为新的默认值 1(当我这样做时,这并没有自动发生)修改了表格)。我第一次尝试:
update T set A=1 where A != 2;
Nada。没用。选定的零行。接下来我尝试:
update T set A=1 where !(A=2);
不,那里也什么也没有。我尝试将它们插入选择中,看看更新是否有问题,但它们也没有返回任何内容。 MySQL 参考手册说 != 和 !是有效的运算符,并且在该上下文中应该完全有效。我终于使用 IS NULL 实现了我的目标,但这些语句应该有效。那么什么给出呢?为什么那不起作用?
我正在运行 MySQL 版本:5.1.41-3ubuntu12.6 (Ubuntu)
I have a table T that has a column A. A started with a default of NULL. 40 rows later, I changed the default to 1. Three rows had a value of 2. I tried to select all the rows where column A where not 2 and set them to the new default of 1 (which hadn't happened automatically when I altered the table). I first tried:
update T set A=1 where A != 2;
Nada. Didn't work. Selected zero rows. Next I tried:
update T set A=1 where !(A=2);
Nope, nothing there either. I tried plugging them into selects, to see if there was something wrong with the update, but those returned nothing either. The MySQL reference manual says that != and ! are valid operators and ought to be perfectly valid in that context. I finally achieved my goal using IS NULL, but those statements should have worked. So what gives? Why didn't that work?
I am running MySQL version: 5.1.41-3ubuntu12.6 (Ubuntu)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试:
涉及
NULL
的比较评估为NULL(UNKNOWN)
因此永远不会是真的。Try:
Comparisons involving
NULL
evaluate toNULL(UNKNOWN)
and will thus never be true.