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)
Updated on: 2020-06-22T06:21:17+05:30

447 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements