Is 'IS DISTINCT FROM' a real MySQL operator?

て烟熏妆下的殇ゞ 提交于 2019-11-28 01:25:00

问题


In one book I see this syntax:

SELECT * FROM inw WHERE id IS DISTINCT FROM 4;

But I get an error:

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

It's an alternative for:

mysql> SELECT * FROM inw WHERE id is null OR id <> 4;
+------+
| id   |
+------+
| NULL |
| NULL |
|    3 |
+------+

Is 'IS DISTINCT FROM' a real MySQL operator?


回答1:


is distinct from is defined in the SQL:2003 standard and is a null-safe operator to compare two values.

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



来源:https://stackoverflow.com/questions/27134368/is-is-distinct-from-a-real-mysql-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!