IN NULL vs IS NULL

This is one more common mistake the one can make when it comes to NULL engaged with comparison

Consider these two statements, they will produce different results:

select * from emp where commission_pct in (0.1, NULL) ; 
select * from emp where commission_pct = 0.1 or commission_pct IS NULL ;

 

In the first statement, NULL won’t be caught, because it is equivalent to

select * from emp where commission_pct = 0.1 or commission_pct = NULL ;

While the second query will work just fine because NULL is being processed correctly

Leave a comment

Your email address will not be published. Required fields are marked *