Lesson 16 +10 XP

BETWEEN Operator

BETWEEN Operator

The BETWEEN operator selects values within a range. The range is inclusive: both endpoints are included.

Numbers

SELECT * FROM Products
WHERE Price BETWEEN 10 AND 20;

Returns products with price 10, 20, and everything in between.

Text

SELECT * FROM Products
WHERE ProductName BETWEEN 'Carnarvon' AND 'Mozzarella';

Uses alphabetical order.

Dates

SELECT * FROM Orders
WHERE OrderDate BETWEEN '2024-01-01' AND '2024-12-31';

NOT BETWEEN

SELECT * FROM Products
WHERE Price NOT BETWEEN 10 AND 20;

Products outside the range.

BETWEEN is inclusive

Price BETWEEN 10 AND 20 includes both 10 and 20. Use strict comparison (> and <) if you want to exclude the endpoints.

TL;DR

  • BETWEEN filters within a range.
  • Both boundaries are included (inclusive).
  • Works with numbers, text, and dates.
  • NOT BETWEEN excludes the range.