문제

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 ?

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top