MySQL provides a nice operator <=>
that works with comparisons that could contain a null such as null <=> null
or null <=> 5
Who really needs an operator that is effectively undefined with built in language types?
you also need it for relations inside your database. specially if you are using foreign key constraints.
for example if you have a table for tasks (in your company). then you assign these tasks to employees. so you have a relation from your tasks-table to your employees-table.
and there will always be some unassigned tasks. in this case the field in your tasks-table you use for the relation to the employees table will contain NULL
.
this will make sure, that this task is unassigned. which means: there is no possibility that there is a relation to the employees table.
if NULL = NULL
would be true
, then in my example there would be always the possibility that the foreign key in the employees table also is NULL
. thus the task would be assigned to one or some employees. and you never would be able to know for sure wheter a task is assigned to some employee or not.