13.1. The BETWEEN Predicate

The predicate <value expression> [NOT] BETWEEN <low value expression> AND <high value expression> is a feature of SQL that is used often enough to deserve special attention. It is also just tricky enough to fool beginning programmers. This predicate is actually just shorthand for the expression:

((<low value expression> <= <value expression>)
  AND (<value expression> <= <high value expression>))

Please note that the end points are included in this definition. This predicate works with any data types that can be compared. Most programmers miss this fact and use it only for numeric values, but it can be used for character strings and temporal data as well. The <high value expression> and <low value expression> can be ...

Get Joe Celko's SQL for Smarties, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.