什么是 MySQL NULL 安全相等运算符,它与比较运算符有何不同?
MySQL NULL 安全相等运算符,等同于标准 SQL IS NOT DISTINCT FROM 运算符,执行与 = 运算符一样的相等比较。其符号是<=>。它在两个操作数都为 NULL 的情况下与比较运算符执行不同。考虑以下示例来理解 NULL 安全运算符以及它与比较运算符之间的差异 -
mysql> Select 50 <=> 50, NULL <=> NULL, 100 <=> NULL; +-----------+---------------+--------------+ | 50 <=> 50 | NULL <=> NULL | 100 <=> NULL | +-----------+---------------+--------------+ | 1 | 1 | 0 | +-----------+---------------+--------------+ 1 row in set (0.00 sec) mysql> Select 50 = 50, NULL = NULL, 100 = NULL; +---------+-------------+------------+ | 50 = 50 | NULL = NULL | 100 = NULL | +---------+-------------+------------+ | 1 | NULL | NULL | +---------+-------------+------------+ 1 row in set (0.00 sec)
广告