Previous Topic: Order of Predicate EvaluationNext Topic: Order of Joins


Non-Matching Rows

Conversely, the following query finds only rows of T1 that do not have a matching T2 row (when T2.c2 is defined as not nullable):

 FROM T1 left join T2 on t1.c1 = t2.c1
 WHERE T2.c2 IS NULL

However, since each matching T2 row is found and then rejected, the following query is more efficient because the NOT EXISTS predicate is evaluated after finding only a single matching row:

 SELECT *
 FROM T1
 WHERE NOT EXISTS (SELECT *
                   FROM T2
                   WHERE T2.c1 = T1.c1)