BETWEEN

Introduction

The BETWEEN operator is used in databases and programming to filter data within a specific range. It helps you select values that fall between two defined limits.

Syntax

SELECT column_name
FROM table_name
WHERE column_name BETWEEN value1 AND value2;
  • column_name – the field you want to filter
  • table_name – the table containing the data
  • value1 – the lower limit of the range
  • value2 – the upper limit of the range

Note: The BETWEEN operator includes both the lower and upper limits.

Examples

  1. Numbers
SELECT * 
FROM Employees
WHERE Age BETWEEN 25 AND 35;

This query retrieves all employees whose age is between 25 and 35, inclusive.

  1. Dates
SELECT * 
FROM Orders
WHERE OrderDate BETWEEN '2026-01-01' AND '2026-03-01';

This query retrieves orders placed between January 1, 2026, and March 1, 2026.

  1. Text
    Some databases allow BETWEEN with text to filter alphabetically.
SELECT * 
FROM Products
WHERE ProductName BETWEEN 'A' AND 'M';

This query retrieves products with names starting from A to M.

Important Points

  • BETWEEN is inclusive of the boundary values.
  • You can use it with numbers, dates, and sometimes text.
  • Equivalent to using >= value1 AND <= value2 but cleaner and easier to read.

Practice Exercise

  1. Retrieve all students with marks between 50 and 80.
  2. List all orders placed between February 1, 2026, and February 28, 2026.

This structure works perfectly for website tutorials, LMS courses, or interactive lessons.

Home » SQL Foundations Program (SQL-101) > Filtering & Conditions > BETWEEN