"IS DISTINCT FROM"是真正的MySQL运算符吗? [英] Is 'IS DISTINCT FROM' a real MySQL operator?
问题描述
在一本书中,我看到了这种语法:
In one book I see this syntax:
SELECT * FROM inw WHERE id IS DISTINCT FROM 4;
但是我得到一个错误:
错误1064(42000):您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第1行的"DISTINCT FROM 4"附近使用
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'DISTINCT FROM 4' at line 1
它可以替代:
mysql> SELECT * FROM inw WHERE id is null OR id <> 4;
+------+
| id |
+------+
| NULL |
| NULL |
| 3 |
+------+
'IS DISTINCT FROM'是真正的MySQL操作员吗?
Is 'IS DISTINCT FROM' a real MySQL operator?
推荐答案
is distinct from
在SQL:2003标准中定义,并且是用于比较两个值的null安全运算符.
is distinct from
is defined in the SQL:2003 standard and is a null-safe operator to compare two values.
MySQL支持空安全等于"运算符:<=>
.如果否定,您将获得相同的行为. (<=>
对应于is not distinct from
)
MySQL supports a "null safe equals" operator: <=>
. If that is negated, you get the same behaviour. (the <=>
corresponds to is not distinct from
)
SELECT *
FROM inw
WHERE not id <=> 4;
SQLFiddle: http://sqlfiddle.com/#!2/0abf2a/3
SQLFiddle: http://sqlfiddle.com/#!2/0abf2a/3
这篇关于"IS DISTINCT FROM"是真正的MySQL运算符吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!