Skip to content
Reference/SQL WHERE Operators
Reference

SQL WHERE Operators

The operators you use to keep only the rows you care about.

WHERE runs once per row and keeps the rows where the condition istrue. Rows where the condition is false orNULL are dropped.

Comparison operators

OperatorMeaningExample
=Equal tostatus = 'shipped'
<> or !=Not equal tostatus <> 'cancelled'
< <=Less than / or equalprice <= 10
> >=Greater than / or equalquantity_on_hand > 0

Combining conditions

AND / OR / parentheses
select *
from   products
where  category_id = 1
  and  (price < 10 or quantity_on_hand = 0)

AND binds tighter than OR, so use parentheses whenever you mix them. Otherwise the query may match far more rows than you expect.

IN vs OR

Use IN when one column can equal any value in a short list. UseOR when the alternatives are different columns or different comparisons.

Equivalent filters
where state = 'PA'
   or state = 'OR'
   or state = 'FL'

where state in ('PA', 'OR', 'FL')

Set, range, and pattern operators

OperatorUseExample
INMatch any value in a liststate in ('PA', 'NY', 'OH')
NOT INMatch none of a liststatus not in ('cancelled', 'refunded')
BETWEENInclusive rangeprice between 10 and 25
LIKEPattern match (% = any, _ = one)product_name like '%seed%'
IS NULLMissing valueshipped_date is null
Watch out

NOT IN behaves surprisingly when the list contains aNULL: it can filter out every row. PreferNOT EXISTS or add ... is not null when the column may be null. See Null handling.

Dialect note

LIKE is case-sensitive in DuckDB and Postgres. UseILIKE for case-insensitive matching in both. In MySQL,LIKE is usually case-insensitive by default.