How do you use the BETWEEN operator?
The BETWEEN
operator in SQL is used to filter the result set within a specific range. It checks whether a value is within a given lower and upper bound (inclusive of both ends).
🔹 Syntax:
column_name BETWEEN lower_bound AND upper_bound
This is equivalent to:
column_name >= lower_bound AND column_name <= upper_bound
🔹 Example 1: Numeric Range
SELECT * FROM employees
WHERE salary BETWEEN 30000 AND 50000;
✅ This query will return all employees whose salary is between 30,000 and 50,000, inclusive.
🔹 Example 2: Date Range
SELECT * FROM orders
WHERE order_date BETWEEN '2024-01-01' AND '2024-12-31';
✅ This fetches all orders placed in the year 2024.
🔹 Example 3: Text Range (Alphabetical)
SELECT * FROM products
WHERE product_name BETWEEN 'A' AND 'M';
✅ This returns all products where the name starts with a letter between A and M.
🔸 Notes:
- The
BETWEEN
operator is inclusive — it includes bothlower_bound
andupper_bound
. - You can use
NOT BETWEEN
to exclude a range:SELECT * FROM employees WHERE salary NOT BETWEEN 30000 AND 50000;
Let me know if you want to try it with real-world data or combine it with JOIN
, ORDER BY
, etc.
At Online Learner, we're on a mission to ignite a passion for learning and empower individuals to reach their full potential. Founded by a team of dedicated educators and industry experts, our platform is designed to provide accessible and engaging educational resources for learners of all ages and backgrounds.
Terms Disclaimer About Us Contact Us
Copyright 2023-2025 © All rights reserved.