I have a table employee which has a column company which has all null values
Now, I want to use a NOT IN operator for the company name as
select * from employee where employee.company NOT IN ('ABC', 'DEF')
Now technically this should not alter the result since the company column already had null values.
But adding the NOT IN gives 0 rows.
Is this due to the fact that employee.company column has NULL values?
Try this way:
select *
from employee E
where (E.company NOT IN ('ABC', 'DEF')
or E.company is null)
SQL uses three valued logic: true, false, and unknown. A comparison with null results in unknown, which is not true.
So a where clause like:
where null in (1,2)
Will not return any rows.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With