thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Intermediate

NOT EXISTS

A predicate that is true when a correlated subquery returns no rows; the NULL-safe way to write an anti join.

Definition

NOT EXISTS stops evaluating as soon as one match is found and handles NULLs correctly, unlike NOT IN. Optimizers usually turn it into an efficient anti join.

Example

WHERE NOT EXISTS (SELECT 1 FROM Returns r WHERE r.OrderID = o.OrderID)

Exam tip

When the subquery column can be NULL, NOT EXISTS returns correct results while NOT IN can return nothing.

Related terms