The WHERE clause applies a Boolean expression to each row produced by the preceding FROM, JOIN, or sub-query step. Only rows for which the expression evaluates to TRUE are returned to the next stage of query processing. WHERE executes before GROUP BY, HAVING, WINDOW functions, and ORDER BY, making it the primary filter for row-level data. It supports comparison operators (=, <, >, <=, >=, <>), logical operators (AND, OR, NOT), pattern matching (LIKE, ILIKE, SIMILAR TO), set membership (IN, NOT IN), null checks (IS NULL, IS NOT NULL), and sub-queries. Numeric, string, date, and even JSON or array data types can be compared as long as the database supports the operator. A NULL comparison without IS NULL returns UNKNOWN, which behaves like FALSE in WHERE, effectively excluding the row. WHERE is available in SELECT, UPDATE, DELETE, and MERGE statements; for aggregated filters, use HAVING instead. Performance depends on indexes on columns referenced in the predicate.
condition
(Boolean expression) - Evaluated per row; rows that return TRUE pass through.HAVING, GROUP BY, JOIN, ORDER BY, DISTINCT, AND, OR, NOT, LIKE, IN
SQL-86 (ANSI X3.135-1986)
Comparison (=, <, >, <=, >=, <>), logical (AND, OR, NOT), pattern matching (LIKE, ILIKE), set membership (IN, NOT IN), NULL checks (IS NULL), and custom operators supported by the database.
WHERE filters before rows are grouped. If you need to filter on aggregate results, use HAVING instead.
Any comparison to NULL using standard operators returns UNKNOWN, which is treated like FALSE. Use IS NULL or IS NOT NULL to correctly include or exclude NULLs.
It depends on the database and collation settings. In PostgreSQL with default collation, comparisons are case sensitive; in MySQL with a case-insensitive collation they are not. Use functions like LOWER() for deterministic behavior.