I do have two tables table1 and table2. And their content as follows
mysql> select id from table1;
+------+
| id |
+------+
| 1 |
| 2 |
| 3 |
| 4 |
+------+
4 rows in set (0.00 sec)
mysql> select id from table2;
+------+
| id |
+------+
| 301 |
| 2 |
| NULL |
+------+
3 rows in set (0.00 sec)
when I hit the below query in mysql console it always returns empty set
select id
from table1
where id
not in (select id from table2);
Empty set (0.00 sec)
Is there a reason when there are null values in the sub query the in and not in would malfunction....?
I've solved it by using the below query
select id
from table1
where id
not in (select id from table2 where id is not null);
+------+
| id |
+------+
| 1 |
| 3 |
| 4 |
+------+
3 rows in set (0.00 sec)
Just want to know
Thanks in advance :)
edit: This question tries to clear some air but not enough