query
NOT EXISTS
NOT EXISTS is true when the subquery produces no rows. With equality correlation, outer NULL keys remain unmatched unless a NULL-safe predicate is chosen.
Formal Syntax & Structure
sql syntaxsql
NOT EXISTS (SELECT ... WHERE ...)Working Example
Example Snippetsql
CREATE TABLE a(id int primary key,k int); CREATE TABLE b(k int); INSERT INTO a VALUES (1,10),(2,20),(3,NULL); INSERT INTO b VALUES (10),(10),(NULL);SELECT id FROM a WHERE NOT EXISTS (SELECT 1 FROM b WHERE b.k=a.k) ORDER BY id;