Why are "Null Like X" and "Not (Null Like X)" equal?
null, sql, sql-like
Solution
SQL uses a three-valued logic. You say that these are all false:
NULL LIKE 'X'
NULL NOT LIKE 'X'
NOT (NULL LIKE 'X')
NOT (NULL NOT LIKE 'X')
but that's actually not true. They're all null, which is neither true nor false.
A `WHEN` or `WHERE` clause rejects non-true values, which means null values as well as false ones, so it may seem like null is the same as false, but as you've noticed, it's not. :-)
Problem
I understand why these 2 statements are false ``` NULL LIKE 'X' NULL NOT LIKE 'X' ``` However, what I don't understand is why these are : ``` NOT (NULL LIKE 'X') NOT (NULL NOT LIKE 'X') ``` For example, these two statements should, I think, return different values : ``` SELECT CASE WHEN NOT (NULL LIKE 'X') THEN 'True' ELSE 'False' END SELECT CASE WHEN (NULL LIKE 'X') THEN 'True' ELSE 'False' END ```