gpt4 book ai didi

mysql - 'IS DISTINCT FROM' 是真正的 MySQL 运算符吗?

转载 作者:可可西里 更新时间:2023-11-01 07:17:57 25 4
gpt4 key购买 nike

在一本书中我看到了这样的语法:

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 运算符吗?

最佳答案

is distinct from是在 SQL:2003 标准中定义的,是用于比较两个值的 null 安全运算符。

MySQL 支持 "null safe equals" operator: <=> .如果否定,你会得到相同的行为。 (<=>对应于is not distinct from)

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

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

关于mysql - 'IS DISTINCT FROM' 是真正的 MySQL 运算符吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27134368/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com