Joe Celko's SQL for Smarties: Advanced SQL Programming, Third Edition

Chapter 13: 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. The BETWEEN predicate works with scalar range limits; 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.

13.1 The BETWEEN Predicate

The predicate [NOT] BETWEEN AND 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:

(( <= )  AND ( <= ))<a name="504"></a><a name="beginpage.BDC2BA02-527A-4DB7-BB08-B3C7624DF4F7"></a>

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 and can be expressions or constants, but again, programmers tend to use just constants.

13.1.1 Results with NULL Values

The results of this predicate with NULL values for , , or follow directly from the definition. If both and are NULL, the result is UNKNOWN for any value of . If or is NULL, but not...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Vacuum Pumps and Vacuum Generators
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.