2012-01-07 11 views

Odpowiedz

16

Spróbuj

select id 
from mytable 
where id not in (select id from another_table); 

lub

select id 
from mytable 
except 
select id 
from another_table; 
+2

Wystarczy marginesie: jeśli 'ìd' może być null w 'another_table', pierwsze zapytanie nie będzie działać. W takim przypadku do selekcji podrzędnej należy dodać "gdzie id nie jest pusty" –

8

Korzystanie z LEFT JOIN IS NULL jest także opcja:

SELECT 
    id 
FROM 
    mytable 
    LEFT JOIN another_table ON mytable.id = another_table.id 
WHERE 
    another_table.id IS NULL; 
Powiązane problemy