Search notes:

Oracle Subquery: IN, NOT IN

Test table and data

create table tq84_a (id number,  txt varchar2(10));
create table tq84_b (id number,  txt varchar2(10));

begin
   insert into tq84_a values (   1, 'one'  );
   insert into tq84_a values (   2, 'two'  );
   insert into tq84_a values (   3, 'three');
   insert into tq84_a values (null, 'null' );

   insert into tq84_b values (   2, 'two'  );
   insert into tq84_b values (   3, 'three');
   insert into tq84_b values (   4, 'four' );
   insert into tq84_b values (null, 'null' );
end;
/

IN

The record whose id is null is not returned:
select * from tq84_a
where
   id in (select id from tq84_b);
--
--         ID TXT       
-- ---------- ----------
--          2 two       
--          3 three     

NOT IN

When the subquery returns one or more null values to the NOT IN operator, no record is returned:
select * from tq84_a
where
   id not in (select id from tq84_b);
--
-- no rows selected
The following query's subquery does not return null values:
select * from tq84_a
where
   id not in (select id from tq84_b where id is not null);
--
        ID TXT       
---------- ----------
         1 one       

Cleaning up

drop   table tq84_a;
drop   table tq84_b;

See also

exists and not exists
Subqueries in the where clause
The plan operators HASH JOIN ANTI and HASH JOIN ANTI NA.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758192001, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/clauses/where/subquery/in_not-in(96): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78