Question

Here is my Table1

personid
1
?
2
3
4
?
6

Here is my query

select * 
from table2
where personid not in 
(
select personid
from table1
)

The result is nothing


Here is my second query

select * 
from table2
where personid not in 
(
select personid
from table1         
where personid is not null
)

The result is ok


Question : why the first query did not work ? I can't see any logical problem . Do nulls skrew up teradata ?

Was it helpful?

Solution

It's not specific to Teradata, it's the same (or at least should be the same) in all RDBMSes. Any comparison to a NULL results in UNKNOWN and NOT IN is an ANDed condition:

personid <> 1st_value_in_list AND personid <> 2nd_value_in_list AND ... AND personid <> NULL

This has been discussed multiple times, e.g. NOT IN clause and NULL values

OTHER TIPS

Yes. If one of the value in the subquery is NULL, the IN clause does not return anything.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top