20

BETWEEN and OVERLAPS Predicates

The BETWEEN and OVERLAPS predicates both offer a shorthand way of showing that one value lies within a range defined by two other values. BETWEEN works with scalar range limits of all types; the OVERLAPS predicate looks at two time periods (defined either by start and end points or by a starting time and an INTERVAL) to see if they overlap in time.

20.1 The BETWEEN Predicate

The BETWEEN predicate is a feature of SQL that is used enough to deserve special attention. It is also just tricky enough to fool beginning programmers.

<between predicate>

 ::= <row value predicand> <between predicate part 2>

<between predicate part 2> ::=

[NOT] BETWEEN [ASYMMETRIC | SYMMETRIC]

<row value predicand> AND <row value predicand> ...

Get Joe Celko's SQL for Smarties, 4th 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.