NOT EXISTS vs NOT IN vs LEFT JOIN IS NULL

Concepts covered: sqlNullInJoins

Here is the shape that recurs in every reporting interview. The interviewer has a customers table and an orders table. They say: 'find customers who have never placed an order.' The query is one of three forms, each four to six lines. The interview signal is not whether you can write the query. It is whether you pick the form that holds up under the conditions of the real data. Why the choice between forms matters Default to NOT EXISTS. The reason is that it handles NULLs in the subquery correctly without an extra clause, reads as 'this thing does not exist,' which matches the English question, and produces the same query plan as NOT IN on most modern engines without the NULL hazard. Saying 'I default to NOT EXISTS because it is NULL-safe and reads like the question' is the answer the inte

About This Interactive Section

This section is part of the Anti-Join: Intermediate lesson on DataDriven, a free data engineering interview prep platform. Each section includes explanations, worked examples, and hands-on code challenges that execute in real time. SQL queries run against a live database. Python runs in a sandboxed Docker container. Data modeling problems validate against interactive schema canvases. All content is framed around what data engineering interviewers actually test at companies like Meta, Google, Amazon, Netflix, Stripe, and Databricks.

How DataDriven Lessons Work

DataDriven combines four interview rounds (SQL, Python, Data Modeling, Pipeline Architecture) with adaptive difficulty and spaced repetition. Easy problems get harder as you improve. Weak concepts resurface until you master them. Your readiness score tracks progress across every topic interviewers test. Every lesson section ends with problems you solve by writing and running real code, not by picking multiple-choice answers.