Tuesday 17 September 2013

Is IN and NOT IN mutually Exclusive?

Is IN and NOT IN mutually Exclusive?

I have two tables
Table 1
Column1
_______
1
2
3
4
5
6
Table 2
Column 1
________
4
NULL //This NULL value added after answering the question, to show the
real problem
5
6
7
8
9
This is an example case. When I tried,
SELECT column1 FROM Table1 WHERE column1 IN (SELECT column1 FROM Table2)
I got 4,5,6
WHEN
SELECT column1 FROM Table1 WHERE column1 NOT IN (SELECT column1 FROM Table2)
I didn't get 1,2,3 instead NULL.
In real case the column1 of table1 is nvarchar(max) and column1 of table2
is varchar(50). However, I tried casting both into varchar(50).

No comments:

Post a Comment