What is MySQL NULL-safe equal operator and how it is different from comparison operator?


MySQL NULL-safe equal operator, equivalent to standard SQL IS NOT DISTINCT FROM operator, performs an equality comparison like = operator. Its symbol is <=>. It performs differently from the comparison operators in the case when we have NULL as both the operands. Consider the following examples to understand NULL-safe operator along with its difference with comparison operator −

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)

Sharon Christine
Sharon Christine

An investment in knowledge pays the best interest

Updated on: 22-Jun-2020

238 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements