BETWEEN

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Tests whether a value falls within an inclusive range. Returns a boolean result.

Syntax 

1<a> BETWEEN <x> AND <y>
2<a> NOT BETWEEN <x> AND <y>
3<a> BETWEEN SYMMETRIC <x> AND <y>
4<a> NOT BETWEEN SYMMETRIC <x> AND <y>

Arguments 

Required 

  • <a>: The value to test.
  • <x>: The lower bound of the range, included in the range.
  • <y>: The upper bound of the range, included in the range.

Returns 

Returns true if <a> falls within the range, and false otherwise. NOT BETWEEN returns the opposite result.

Considerations 

  • a BETWEEN x AND y is equivalent to a >= x AND a <= y. BETWEEN treats the endpoint values as included in the range.
  • NOT BETWEEN does the opposite comparison: a NOT BETWEEN x AND y is equivalent to a < x OR a > y.
  • BETWEEN SYMMETRIC first sorts the two bounds, so their order doesn’t matter: a BETWEEN SYMMETRIC x AND y tests whether a falls between the smaller and the larger of x and y. NOT BETWEEN SYMMETRIC is its negation.

Examples 

Test a Numeric Range 

1SELECT 5 BETWEEN 1 AND 10 AS result;

Returns true.

Exclude a Range 

1SELECT col1
2FROM tab1
3WHERE col1 NOT BETWEEN 0 AND 100;

Test a Range with Unordered Bounds 

1SELECT 5 BETWEEN SYMMETRIC 10 AND 1 AS result;

Returns true because BETWEEN SYMMETRIC sorts the bounds before testing, so 5 is compared against the range 1 to 10.

Related Documentation