O'Reilly logo

SQL: Visual QuickStart Guide by Chris Fehily

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Range Filtering with BETWEEN

Use BETWEEN to determine whether a given value falls within a specified range. The BETWEEN condition’s important characteristics are:

  • BETWEEN works with character strings, numbers, and datetimes.

  • The BETWEEN range contains a low value and a high value, separated by AND. The low value must be less than or equal to the high value.

  • BETWEEN is a convenient, shorthand clause. You can replicate its behavior by using AND:

    WHERE test_column BETWEEN
          low_value AND high_value
    						

    is equivalent to:

    WHERE (test_column >= low_value)
      AND (test_column <= high_value)
    
  • BETWEEN specifies an inclusive range, in which the high value and low value are included in the search. To specify an exclusive range, which excludes endpoints, use > and ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required