数据库
首页 > 数据库> > ‘IS DISTINCT FROM’是一个真正的MySQL操作符吗?

‘IS DISTINCT FROM’是一个真正的MySQL操作符吗?

作者:互联网

在一本书中,我看到了这种语法:

SELECT * FROM inw WHERE id IS 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操作符吗?

解决方法:

与SQL:2003标准中定义的不同,是一个比较两个值的null安全运算符.

MySQL支持“null safe equals”运算符:< =>.如果否定,则会得到相同的行为. (< =>对应于不相同)

SELECT * 
FROM inw 
WHERE not id <=> 4;

SQLFiddle:http://sqlfiddle.com/#!2/0abf2a/3

标签:mysql,logical-operators
来源: https://codeday.me/bug/20190728/1560571.html