It:
Error not in ('Timeout','Connection Error');
semantically equivalent:
Error <> 'TimeOut' AND Error <> 'Connection Error'
Zero comparison rules also apply to IN. Therefore, if the Error value is NULL, the database cannot make the expression true.
To fix this, you can do the following:
COALESCE(Error,'') not in ('Timeout','Connection Error');
Or even better:
Error IS NULL OR Error not in ('Timeout','Connection Error');
Or even better:
CASE WHEN Error IS NULL THEN 1 ELSE Error not in ('Timeout','Connection Error') THEN 1 END = 1
OR
does not close, CASE may somehow short-circuit your request
Perhaps a concrete example might show why NULL NOT IN expression
returns nothing:
Given this data: http://www.sqlfiddle.com/#!2/0d5da/11
create table tbl ( msg varchar(100) null, description varchar(100) not null ); insert into tbl values ('hi', 'greet'), (null, 'nothing');
And you make this expression:
select 'hulk' as x, msg, description from tbl where msg not in ('bruce','banner');
This will only output hi.
NOT IN translates to:
select 'hulk' as x, msg, description from tbl where msg <> 'bruce' and msg <> 'banner';
NULL <> 'bruce'
cannot be defined, not even true, not even false
NULL <> 'banner'
cannot be defined, not even true, not even false
So, a null value expression is effectively resolved:
can't be determined AND can't bedetermined
In fact, if your RDBMS supports boolean on SELECT (e.g. MySQL, Postgresql), you can understand why: http://www.sqlfiddle.com/#!2/d41d8/828
select null <> 'Bruce'
Returns null.
This also returns null:
select null <> 'Bruce' and null <> 'Banner'
Given that you are using NOT IN
, which is basically an AND expression.
NULL AND NULL
Results in NULL. So how do you do: http://www.sqlfiddle.com/#!2/0d5da/12
select * from tbl where null
Nothing will be returned