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
BETWEENoperator is inclusive — it includes bothlower_boundandupper_bound. - You can use
NOT BETWEENto 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.
Written by Shaikh Abdul Shahid
A Full-Stack Developer with experience in PHP, Laravel, JavaScript, and React.
Founder of Online Learner, sharing practical knowledge and programming tutorials.
Building and maintaining real-world web applications since 2017.
Your Feedback
Help us improve by sharing your thoughts
Online Learner helps developers master programming, database concepts, interview preparation, and real-world implementation through structured learning paths.
Quick Links
© 2023 - 2026 OnlineLearner.in | All Rights Reserved.
