SQL NOT is a unary logical operator that inverts the truth value of the predicate that follows it. It supports three-valued logic, so NOT TRUE returns FALSE, NOT FALSE returns TRUE, and NOT UNKNOWN (NULL) remains UNKNOWN. NOT can precede any boolean expression or keyword predicate such as IN, BETWEEN, LIKE, or EXISTS, creating forms like NOT IN or NOT EXISTS. Operator precedence places NOT above AND and OR, so NOT condition AND other_condition is evaluated as (NOT condition) AND other_condition unless parentheses change the order. NOT is valid in SELECT, UPDATE, DELETE, MERGE, HAVING, CHECK constraints, CASE expressions, and anywhere a boolean expression is allowed. An expression that evaluates to NULL remains NULL after NOT, which can affect filter results in unexpected ways. Most SQL dialects treat NOT as a reserved keyword.
AND, OR, WHERE, EXISTS, NOT EXISTS, IN, NOT IN, LIKE, NOT LIKE, BETWEEN, NOT BETWEEN, Boolean logic, Three-valued logic
SQL-86 (ANSI X3.135-1986)
NOT IN evaluates the right-hand list once and fails if any NULL is present, potentially returning no rows. NOT EXISTS checks each candidate row individually and is generally safer with NULLs and correlated subqueries.
SQL uses three-valued logic. If the operand of NOT is NULL (UNKNOWN), the result remains UNKNOWN. To ensure rows with NULLs are included or excluded, combine NOT with IS NULL or IS NOT NULL tests.
Yes. NOT is evaluated before AND, which is evaluated before OR. Use parentheses to override default precedence and to make complex logic more readable.
Absolutely. A CHECK (NOT condition) constraint enforces that the condition is false for every row inserted or updated in the table.