NOT IN
NOT IN is a SQL predicate that tests whether a value is absent from a specified list or subquery result, subject to null semantics.
PostgreSQL Mistakes and How to Avoid Them
NOT IN is a SQL predicate that tests whether a value is absent from a set of values or subquery results, subject to SQL null semantics.
- How it is used
- Uses a negative predicate to exclude matching values, especially for small constant lists or carefully constrained subqueries.
- How deep it goes
- Explains predicate behavior, NULL failures, diagnosis, plan changes, and NOT EXISTS and anti-join alternatives.
- Examples
- Demonstrates constant lists, supplier states, NULL-state diagnosis, customer emails, and EXPLAIN output.
- What you can do after
- Diagnose NULL-sensitive exclusions, choose NOT EXISTS, and inspect PostgreSQL plans for scalability.
Read how PostgreSQL Mistakes and How to Avoid Them explains NOT IN →
Learn SQL in a Month of Lunches
The NOT IN operator is an SQL membership operator that tests whether an expression matches none of the values in a specified list or set.
- How it is used
- Filters rows by excluding values from a literal list or the results of a subquery.
- How deep it goes
- Demonstrates list and subquery forms, contrasts ANY and ALL, and notes subquery processing costs.
- Examples
- Uses excluded prices, titles absent from order 1034, and equivalent single-value exclusion conditions.
- What you can do after
- Apply it in SQL to exclude known values or values returned by another query.
Related concepts
- subqueryuses · A subquery is a query embedded within another query or statement whose result contributes to evaluating the containing operation.
- missing valueuses · A missing value is an expected data value or observation that is absent, unavailable, unknown, or inapplicable.
- membership operatoralternative to · A membership operator is a language construct that tests whether a specified value or property is present in a supported collection, range, or object.
Questions about NOT IN
What is NOT IN?
NOT IN is a SQL predicate that tests whether a value is absent from a specified list or subquery result, subject to null semantics.
Which Manning books explain NOT IN?
PostgreSQL Mistakes and How to Avoid Them and Learn SQL in a Month of Lunches.
What is the difference between NOT IN and NOT EXISTS?
NOT IN is a SQL predicate that tests whether a value is absent from a specified list or subquery result, subject to null semantics. NOT EXISTS is a query predicate that is true when its specified subquery or condition yields no matching rows.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

