与标准SQL IS NOT DISTINCT FROM运算符等效的MySQL NULL安全相等运算符执行等于运算符的相等比较。其符号为<=>。当我们两个操作数都为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)