Notes
Categories

BETWEEN Operator in SQL [ English ]

< Prev Next >

📌 Definition

The BETWEEN operator is used in a WHERE clause to filter records within a specified range of values.

👉 It selects values between two limits (inclusive).

🧠 Syntax

SELECT column_name
FROM table_name
WHERE column_name BETWEEN value1 AND value2;

🔑 Important Concept

👉 Equivalent to:

column_name >= value1 AND column_name <= value2

📊 Example Table: Students

ID Name Age
1 Amit 18
2 Riya 21
3 Rahul 19
4 Neha 23
5 Karan 20

1. BETWEEN with Numbers

✅ Example

SELECT * FROM Students
WHERE Age BETWEEN 19 AND 21;

📌 Result

💡 Explanation

Returns all students whose age is between 19 and 21 (inclusive).


2. BETWEEN with Strings

📌 Definition

BETWEEN can also be used with text (alphabetical range).

✅ Example

SELECT * FROM Students
WHERE Name BETWEEN 'A' AND 'M';

💡 Explanation


3. BETWEEN with Dates

✅ Example

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

💡 Explanation


⚠️ Important Notes

1. Inclusive Nature

BETWEEN 10 AND 20

👉 Includes 10 and 20 both


2. Order Matters

BETWEEN 20 AND 10

👉 This will return no result (invalid range)


3. Use with NOT

You can exclude a range:

SELECT * FROM Students
WHERE Age NOT BETWEEN 19 AND 21;

👉 Returns values outside the range


🔄 Equivalent Form

SELECT * FROM Students
WHERE Age >= 19 AND Age <= 21;

👉 Same as:

WHERE Age BETWEEN 19 AND 21;

📊 Summary Table

Usage Type Example Meaning
Numbers Age BETWEEN 10 AND 20 Range of numbers
Strings Name BETWEEN 'A' AND 'M' Alphabetical range
Dates Date BETWEEN '2024-01-01' AND '2024-12-31' Date range

🎯 Key Insight

The BETWEEN operator simplifies range conditions and makes queries:

< Prev Next >