SQL Joins and Subqueries/Find missing related rows

Use LEFT JOIN plus NULL filtering to find unmatched rows.

Section: Join Conditions and Filters

Find missing related rows

sql
sql
SELECT c.customer_id
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
WHERE o.order_id IS NULL;
Explanation

This is a common anti-join pattern.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing Join Conditions and Filters
Join with additional predicate
Add extra conditions to the join itself.
OpenIn sheetsqlsame section
Join to an aggregated subquery
Pre-aggregate a table and join the result.
OpenIn sheetsqlsame section
Use a subquery in WHERE
Filter rows based on results from another query.
Filter with EXISTS
Return rows when a related row exists.
Scalar subquery
Return a single value from a nested query.
Filter with NOT EXISTS
Return rows with no related matches.