Why in SQL NULL can't match with NULL?
Rule : Not even a NULL can be equal to NULL.
A Non-Technical aspect
If you ask two girls, how old they are? may be you would hear them to refuse to answer your question, Both girls are giving you NULL as age and this doesn't mean both have similar age. So there is nothing can be equal to null.
NULL
indicates an absence of a value. The designers of SQL decided that it made sense that, when asked whether A
(for which we do not know its value) and B
(for which we do not know its value) are equal, the answer must be UNKNOWN
- they might be equal, they might not be. We do not have adequate information to decide either way.
You might want to read up on Three valued logic - the possible results of any comparison in SQL are TRUE
, FALSE
and UNKNOWN
(mysql treats UNKNOWN
and NULL
as synonymous. Not all RDBMSs do)
NULL
is an unknown value. Therefore it makes little sense to judge NULL == NULL
. That's like asking "is this unknown value equal to that unknown value" - no clue..
See why is null not equal to null false for a possibly better explaination