The NULL
is the undefined, undetermined and indefinable. It is not false, but neither is it true. Neither 8 nor 80. It is not a value, but the lack of one. Because it is not a value, it can be considered a state. A state of indefinite.
By having this definition, by comparing NULL
using the standard comparators (equal, different from, greater than, less than, greater than, equal to, less than) will always result in false
.
SELECT NULL = 0 // => false
SELECT NULL != 0 // => false
SELECT NULL = NULL // => false
Anything that compares to NULL
, is false. This explains why NULL
is the absence of value, the undefined and the lack of a value.
To better understand, I like to say that evalua to false why it is not possible to affirm that it is true.
Think of a hypothetical table in a database, which holds records of people:
+----+-------+-------+
| ID | Nome | Idade |
+----+-------+-------+
| 1 | João | NULL |
| 2 | Maria | 19 |
| 3 | José | NULL |
+----+-------+-------+
Then I ask the following questions to the database:
How old is Maria? 19.
How old is João? I don’t know.
Mary and John are the same age? I can’t say that. Neither false nor true.
The same happens (3) with the question "John and Joseph are the same age?".
That is why comparisons with NULL
need special treatment. And then came the IS NULL
.
Null is absence of information , nothing can be equal to null not even null , the correct syntax is IS NULL , if A is null and B is null A=B returns false for example.
– Motta
related https://answall.com/questions/87514/null-%C3%A9-equals-a-n
– user60252
The result depends on the configuration of ANSI_NULLS
– José Diz