WHERE clause
The WHERE clause keeps the rows for which condition is true. Rows for which the condition is false or NULL are left out. The condition can use the columns of the FROM clause, the aliases of the select list, and subqueries, but not aggregate or window functions. To filter on aggregates, use HAVING, and to filter on window functions, use QUALIFY.
Syntax
WHERE condition
Examples
For a description of the sample tables that the examples on this page use, see SELECT statement in DuckDB.
The following SQL query returns the orders in the east region with an amount over 40. The order with a NULL amount is left out, because comparing NULL with 40 does not return true.
SELECT order_id, customer, amount FROM sales_db.sales_parquet WHERE region = 'east' AND amount > 40 ORDER BY order_id
The query returns the following results.
| order_id | customer | amount |
|---|---|---|
|
|
|
|
|
|
The following SQL query filters on doubled, an alias defined in the select list.
SELECT order_id, amount * 2 AS doubled FROM sales_db.sales_parquet WHERE doubled > 200 ORDER BY order_id
The query returns the following results.
| order_id | doubled |
|---|---|
|
|
|
|
The following SQL query returns the order whose amount is NULL.
SELECT order_id, customer FROM sales_db.sales_parquet WHERE amount IS NULL
The query returns the following result.
| order_id | customer |
|---|---|
|
|