0
0
SQLquery~5 mins

WHERE with BETWEEN range in SQL

Choose your learning style9 modes available
Introduction

The WHERE with BETWEEN range helps you find rows where a value falls between two limits. It makes searching easier when you want to check if something is inside a range.

Finding all sales made between two dates.
Getting products priced between $10 and $50.
Listing students with scores between 70 and 90.
Selecting events happening between two times.
Filtering employees with ages between 25 and 35.
Syntax
SQL
SELECT column1, column2, ...
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

The BETWEEN keyword includes both value1 and value2 in the search.

It works for numbers, dates, and text (alphabetical order).

Examples
Finds products with prices from 10 to 50, including 10 and 50.
SQL
SELECT * FROM products WHERE price BETWEEN 10 AND 50;
Finds orders placed in January 2024.
SQL
SELECT * FROM orders WHERE order_date BETWEEN '2024-01-01' AND '2024-01-31';
Finds students with scores between 70 and 90.
SQL
SELECT * FROM students WHERE score BETWEEN 70 AND 90;
Sample Program

This creates a table of employees, adds some data, and then selects employees aged between 25 and 35.

SQL
CREATE TABLE employees (
  id INT,
  name VARCHAR(50),
  age INT
);

INSERT INTO employees (id, name, age) VALUES
(1, 'Alice', 24),
(2, 'Bob', 30),
(3, 'Charlie', 35),
(4, 'Diana', 40);

SELECT name, age FROM employees WHERE age BETWEEN 25 AND 35;
OutputSuccess
Important Notes

BETWEEN is inclusive, so it includes the boundary values.

You can use NOT BETWEEN to find values outside the range.

Make sure the data types of the column and values match (e.g., dates with dates).

Summary

BETWEEN helps filter rows within a range easily.

It works with numbers, dates, and text.

It includes the start and end values in the results.