-
question about NOT IN
Let say I have two table named ONE and TWO:
tables one one column TEST with 4 rows: A,B,C,null
table two had one column TEST with 4 rows: A,B,C,D
If I query :
select test from TWO
where test IN (select test from ONE)
which returns A,B,C
If I query
select test from TWO
where test NOT IN (select test from ONE)
and I got the null value, why ???? I thought I will get the D value instead
-
Expected. It's because of NULL.
Code:
sanjay@ORAM> select table_name from user_tables;
TABLE_NAME
------------------------------
PLAN_TABLE
T1
T2
TEST
TEST1
sanjay@ORAM> select table_name from user_tables where table_name not in (null);
no rows selected
sanjay@ORAM>
Sanjay G.
Oracle Certified Professional 8i, 9i.
"The degree of normality in a database is inversely proportional to that of its DBA"
-
You can use NVL function or minus operator to get the correct result
Shailendra
-
....or "IS NOT NULL" clause
funky...
"I Dont Want To Follow A Path, I would Rather Go Where There Is No Path And Leave A Trail."
"Ego is the worst thing many have, try to overcome it & you will be the best, if not good, person on this earth"
-
I agree that I can use some other function to get the result I want, I was curious how does SQL work and the logic if someone can give the explanation.
thanks
-
I agree it's far from intuitive - I suppose the test for the row with D beomes:
'D'<>'A' AND 'D'<>'B' AND 'D'<>'C' AND 'D'<>NULL
'D'<>NULL is false (so is 'D'=NULL, and so is NOT 'D'=NULL etc etc) . . . .
I always start by coding these as NOT EXISTS, which behaves as I expect - 9 times out of 10 it's faster too.
Last edited by DaPi; 07-24-2003 at 09:26 AM.
-
Originally posted by DaPi
I always start by coding these as NOT EXISTS, which behaves as I expect - 9 times out of 10 it's faster too.
Yep, me too!
Tomaž
"A common mistake that people make when trying to design something completely
foolproof is to underestimate the ingenuity of complete fools" - Douglas Adams
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|