BETWEEN is a comparison operator used in the WHERE or HAVING clause to filter results to rows whose tested expression lies inclusively between two boundary values. The operator works with numeric, string, date, time, and timestamp data types as long as the expression and bounds are comparable.BETWEEN is evaluated as: expression >= lower_bound AND expression <= upper_bound. Because the bounds are inclusive, both endpoints are kept if they exist in the data set. NOT BETWEEN performs the opposite comparison.Null values in the tested expression or bounds yield UNKNOWN, so those rows are not returned unless IS NULL logic is added separately. The lower and upper bounds can be expressions, constants, or columns, but their evaluation order matters: most optimizers rewrite BETWEEN to two separate comparisons and may leverage indexes on the tested column for performance.If the lower bound is greater than the upper bound, the predicate always evaluates to false (no rows) in most implementations. Some dialects allow symmetric syntax (e.g., BETWEEN SYMMETRIC in PostgreSQL) to avoid this pitfall.BETWEEN is part of the SQL-92 core specification and is supported by virtually every relational database.
expression
- any comparable column or scalar expression to testlower_bound
- literal, column, or expression representing the inclusive minimumupper_bound
- literal, column, or expression representing the inclusive maximumSQL NOT BETWEEN, SQL IN, SQL =, SQL >=, SQL <=, SQL LIKE, SQL WHERE
SQL-92
Yes. The operator keeps rows that are greater than or equal to the lower bound and less than or equal to the upper bound.
Absolutely. String comparisons use the database's collation rules, so ranges follow lexicographic order. Be mindful of case sensitivity.
Most optimizers rewrite NOT BETWEEN to two separate comparisons joined by OR, so indexes can still be used if applicable.
No. If the tested expression or either bound is NULL, the result is UNKNOWN, and the row is excluded unless explicitly checked with IS NULL.