NOT EXISTS
- это то, что вам, вероятно, нужно:
SQL> with customer (id, name) as
2 (select 1, 'a' from dual union all
3 select 2, 'b' from dual union all
4 select 3, 'c' from dual union all
5 select 4, 'd' from dual
6 ),
7 torder (id, customerid, productname) as
8 (select 1, 2, 'abc' from dual union all
9 select 2, 2, 'def' from dual union all
10 select 3, 4, 'abc' from dual union all
11 select 4, 5, 'fgh' from dual
12 )
13 select c.id
14 from customer c
15 where not exists (select null
16 from torder t
17 where t.customerid = c.id);
ID
----------
3
1
SQL>
или MINUS
оператор набора (худшая производительность, чем NOT EXISTS
):
select c.id from customer c
minus
select t.customerid from torder t;