I was trying to filter out some predefined values from a table sample which has two column col1 and col2.
My query:
select *
from sample
where (col1 is not null or col2 is not null)
and col1 not in (1,2)
and col2 not in (3,4);
However, the above query filter out all the null values (in col1 or col2 ).
Example: the below row is filtered out,
col1 col2
---------
7 null
null 8
I get the expected result when i modify the query to below.
select *
from sample
where (col1 is not null or col2 is not null)
and (col1 not in (1,2) or col1 is null)
and (col2 not in (3,4) or col2 is null);
Why NOT IN filters out rows with NULL value even though I am not specified NULL in NOT IN ?