SQL BETWEEN Operator Practice Questions with Solutions

The SQL BETWEEN operator is used to filter records that fall within a specified range. It is a simple and efficient way to retrieve values between two limits without writing multiple comparison operators. SQL BETWEEN Operator practice questions with solutions help to understand the concepts.

The BETWEEN operator works with:

  • Numbers
  • Dates
  • Text (Alphabetical Range)

For example, if you want to display students whose marks are between 80 and 90, instead of writing:

SELECT *

FROM students

WHERE marks >= 80
AND marks <= 90;

You can simply write:

SELECT *

FROM students

WHERE marks BETWEEN 80 AND 90;

The BETWEEN operator includes both boundary values, making it an inclusive operator.

It is commonly used in:

  • Student Result Analysis
  • Salary Reports
  • Sales Reports
  • Banking Applications
  • Employee Management
  • Inventory Systems
  • E-commerce Filters
  • Business Intelligence Dashboards

What is the SQL BETWEEN Operator?

The BETWEEN operator checks whether a value falls within a specified range.

Basic Syntax

SELECT column_name

FROM table_name

WHERE column_name BETWEEN value1 AND value2;

Example

SELECT *

FROM students

WHERE marks BETWEEN 80 AND 90;

This query returns students whose marks are between 80 and 90, including both 80 and 90.


Why Use BETWEEN?

The BETWEEN operator helps you:

  • Write shorter queries
  • Improve readability
  • Replace multiple comparison operators
  • Filter ranges efficiently
  • Generate reports quickly
  • Analyze grouped data

Sample Table Used Throughout This Chapter

students

idnameagecoursecitymarks
101Rahul21PythonDelhi88
102Amit22JavaNoida91
103Neha20SQLDelhi95
104Priya23PythonGurgaon84
105Rohit21JavaFaridabad90
106Ankit22PythonDelhi82
107Sneha21SQLNoida89

1. SQL Query to Display Students Scoring Between 80 and 90

Problem Statement

Write an SQL query to display students whose marks are between 80 and 90.


SQL Solution

SELECT *

FROM students

WHERE marks BETWEEN 80 AND 90;

Sample Output

idnamemarks
101Rahul88
104Priya84
105Rohit90
106Ankit82
107Sneha89

Explanation

The query returns students whose marks fall between 80 and 90, including both values.

It is equivalent to:

SELECT *

FROM students

WHERE marks >= 80
AND marks <= 90;

Concepts Covered

  • BETWEEN Operator
  • Numeric Range
  • Inclusive Range

2. SQL Query to Display Students Aged Between 21 and 22

Problem Statement

Write an SQL query to display students whose age is between 21 and 22 years.


SQL Solution

SELECT *

FROM students

WHERE age BETWEEN 21 AND 22;

Sample Output

idnameagecity
101Rahul21Delhi
102Amit22Noida
105Rohit21Faridabad
106Ankit22Delhi
107Sneha21Noida

Explanation

The query filters all students whose age lies between 21 and 22, including both values.

This type of filtering is frequently used in reporting and analytics.


Concepts Covered

  • BETWEEN
  • Numeric Filtering
  • Range Queries

3. SQL Query to Display Marks Between 85 and 95

Problem Statement

Write an SQL query to display students whose marks are between 85 and 95.


SQL Solution

SELECT *

FROM students

WHERE marks BETWEEN 85 AND 95;

Sample Output

idnamemarks
101Rahul88
102Amit91
103Neha95
105Rohit90
107Sneha89

Explanation

The BETWEEN operator includes both 85 and 95.

Students whose marks fall inside this range are returned.


Concepts Covered

  • BETWEEN
  • Numeric Comparison
  • Inclusive Filtering

4. SQL Query Using BETWEEN with Student IDs

Problem Statement

Write an SQL query to display students whose Student IDs are between 102 and 106.


Sample Table

idnamecoursecitymarks
101RahulPythonDelhi88
102AmitJavaNoida91
103NehaSQLDelhi95
104PriyaPythonGurgaon84
105RohitJavaFaridabad90
106AnkitPythonDelhi82
107SnehaSQLNoida89

SQL Solution

SELECT *

FROM students

WHERE id BETWEEN 102 AND 106;

Sample Output

idnamecoursecitymarks
102AmitJavaNoida91
103NehaSQLDelhi95
104PriyaPythonGurgaon84
105RohitJavaFaridabad90
106AnkitPythonDelhi82

Explanation

The BETWEEN operator checks whether the Student ID lies between 102 and 106, including both values.

This query is useful for:

  • Displaying records within a specific ID range
  • Batch processing
  • Data verification

Concepts Covered

  • BETWEEN
  • Numeric Range
  • Record Filtering

5. SQL BETWEEN with ORDER BY

Problem Statement

Write an SQL query to display students whose marks are between 80 and 95, sorted by marks in descending order.


SQL Solution

SELECT *

FROM students

WHERE marks BETWEEN 80 AND 95

ORDER BY marks DESC;

Sample Output

idnamemarks
103Neha95
102Amit91
105Rohit90
107Sneha89
101Rahul88
104Priya84
106Ankit82

Explanation

The query performs two operations:

  1. Filters students whose marks fall between 80 and 95.
  2. Sorts the filtered records in descending order based on marks.

This type of query is useful for generating ranked reports within a specific score range.


Concepts Covered

  • BETWEEN
  • ORDER BY
  • DESC
  • Sorting Filtered Records

6. SQL BETWEEN with WHERE Clause

Problem Statement

Write an SQL query to display students whose marks are between 85 and 95 and who are enrolled in the Java course.


Sample Table

idnamecoursecitymarks
101RahulPythonDelhi88
102AmitJavaNoida91
103NehaSQLDelhi95
104PriyaPythonGurgaon84
105RohitJavaFaridabad90
106AnkitPythonDelhi82
107SnehaSQLNoida89

SQL Solution

SELECT *

FROM students

WHERE marks BETWEEN 85 AND 95
AND course = 'Java';

Sample Output

idnamecoursecitymarks
102AmitJavaNoida91
105RohitJavaFaridabad90

Explanation

The query performs two operations:

  1. Filters students whose marks are between 85 and 95.
  2. Displays only students enrolled in the Java course.

Both conditions must be satisfied.


Concepts Covered

  • BETWEEN
  • WHERE
  • AND
  • Multiple Conditions

7. SQL BETWEEN with Multiple Conditions

Problem Statement

Write an SQL query to display students:

  • Whose age is between 21 and 22
  • And whose marks are between 80 and 90

SQL Solution

SELECT *

FROM students

WHERE age BETWEEN 21 AND 22
AND marks BETWEEN 80 AND 90;

Sample Output

idnameagemarks
101Rahul2188
105Rohit2190
106Ankit2282
107Sneha2189

Explanation

The query applies two BETWEEN conditions simultaneously:

  • Age between 21 and 22
  • Marks between 80 and 90

Only records satisfying both conditions are displayed.


Concepts Covered

  • BETWEEN
  • Multiple Conditions
  • AND

8. SQL Query to Display Students Aged Between 20 and 23

Problem Statement

Write an SQL query to display students whose age is between 20 and 23 years.


SQL Solution

SELECT *

FROM students

WHERE age BETWEEN 20 AND 23;

Sample Output

idnameage
101Rahul21
102Amit22
103Neha20
104Priya23
105Rohit21
106Ankit22
107Sneha21

Explanation

Since every student’s age falls within the range 20–23, all records are returned.

The BETWEEN operator includes both the starting and ending values.


Concepts Covered

  • BETWEEN
  • Numeric Range
  • Inclusive Filtering

9. SQL BETWEEN with Course Filter

Problem Statement

Write an SQL query to display Python students whose marks are between 80 and 90.


SQL Solution

SELECT *

FROM students

WHERE course = 'Python'
AND marks BETWEEN 80 AND 90;

Sample Output

idnamecoursemarks
101RahulPython88
104PriyaPython84
106AnkitPython82

Explanation

The query first selects students enrolled in Python.

Then it filters those whose marks fall between 80 and 90.


Concepts Covered

  • BETWEEN
  • WHERE
  • AND
  • Text Filtering

10. SQL BETWEEN with City Filter

Problem Statement

Write an SQL query to display students from Delhi whose marks are between 80 and 95.


SQL Solution

SELECT *

FROM students

WHERE city = 'Delhi'
AND marks BETWEEN 80 AND 95;

Sample Output

idnamecitymarks
101RahulDelhi88
103NehaDelhi95
106AnkitDelhi82

Explanation

The query combines:

  • City filter (Delhi)
  • Marks range (80–95)

Only students satisfying both conditions are displayed.


Concepts Covered

  • BETWEEN
  • WHERE
  • AND
  • Range Filtering

11. SQL BETWEEN with ORDER BY DESC

Problem Statement

Write an SQL query to display students whose marks are between 80 and 95, sorted by marks in descending order.


Sample Table

idnamecoursecitymarks
101RahulPythonDelhi88
102AmitJavaNoida91
103NehaSQLDelhi95
104PriyaPythonGurgaon84
105RohitJavaFaridabad90
106AnkitPythonDelhi82
107SnehaSQLNoida89

SQL Solution

SELECT *

FROM students

WHERE marks BETWEEN 80 AND 95

ORDER BY marks DESC;

Sample Output

idnamemarks
103Neha95
102Amit91
105Rohit90
107Sneha89
101Rahul88
104Priya84
106Ankit82

Explanation

The query performs two operations:

  1. Filters students whose marks lie between 80 and 95.
  2. Sorts the filtered records from highest marks to lowest marks.

This query is useful for creating performance reports within a specified score range.


Concepts Covered

  • BETWEEN
  • ORDER BY
  • DESC
  • Sorting Records

12. SQL BETWEEN with LIMIT

Problem Statement

Write an SQL query to display the first three students whose marks are between 80 and 95.


SQL Solution

SELECT *

FROM students

WHERE marks BETWEEN 80 AND 95

LIMIT 3;

Sample Output

idnamemarks
101Rahul88
102Amit91
103Neha95

Explanation

The query first filters records using the BETWEEN operator.

After filtering, the LIMIT clause returns only the first three matching records.

This approach is commonly used for previews and pagination.


Concepts Covered

  • BETWEEN
  • LIMIT
  • Data Preview

13. SQL BETWEEN on Text Values

Problem Statement

Write an SQL query to display students whose names fall alphabetically between A and M.


SQL Solution

SELECT *

FROM students

WHERE name BETWEEN 'A' AND 'M';

Sample Output

idname
102Amit
106Ankit

Explanation

The BETWEEN operator also works with text values.

SQL compares strings alphabetically based on the database collation.

Names beginning with letters between A and M are returned.


Concepts Covered

  • BETWEEN
  • Text Comparison
  • Alphabetical Range

14. SQL NOT BETWEEN

Problem Statement

Write an SQL query to display students whose marks are not between 80 and 90.


SQL Solution

SELECT *

FROM students

WHERE marks NOT BETWEEN 80 AND 90;

Sample Output

idnamemarks
102Amit91
103Neha95

Explanation

NOT BETWEEN returns records whose values fall outside the specified range.

It is the opposite of the BETWEEN operator.


Concepts Covered

  • NOT BETWEEN
  • Range Exclusion
  • Filtering Records

15. Real-World SQL BETWEEN Example

Problem Statement

A school wants to generate a report of students scoring between 85 and 95 marks.

Write an SQL query to retrieve these students.


SQL Solution

SELECT *

FROM students

WHERE marks BETWEEN 85 AND 95;

Sample Output

idnamecoursemarks
101RahulPython88
102AmitJava91
103NehaSQL95
105RohitJava90
107SnehaSQL89

Explanation

This query is useful for generating:

  • Merit Lists
  • Student Performance Reports
  • Scholarship Eligibility Lists
  • Department Reports
  • Academic Dashboards

The BETWEEN operator makes range-based filtering simple and easy to understand.


Concepts Covered

  • BETWEEN
  • Real-world SQL Queries
  • Report Generation
  • Range Filtering

Chapter Summary

In this chapter, you learned how to use the SQL BETWEEN operator to retrieve records that fall within a specified range. Instead of writing multiple comparison operators such as >= and <=, the BETWEEN operator provides a shorter and more readable way to filter data.

One important point to remember is that BETWEEN is inclusive, meaning it includes both the starting and ending values of the range.

During this chapter, you practiced using the BETWEEN operator with:

  • Numeric values
  • Student IDs
  • Marks
  • Age
  • Text values
  • WHERE
  • ORDER BY
  • LIMIT
  • NOT BETWEEN
  • Real-world reporting examples

The BETWEEN operator is one of the most useful SQL operators for filtering ranges in business reports, dashboards, and analytical queries.


Key Takeaways

  • The BETWEEN operator filters values within a range.
  • BETWEEN includes both boundary values.
  • It replaces >= and <= conditions.
  • It works with numbers, dates, and text.
  • BETWEEN is commonly used with the WHERE clause.
  • It can be combined with ORDER BY and LIMIT.
  • NOT BETWEEN returns values outside the specified range.
  • It improves query readability.
  • It is useful for reports and dashboards.
  • It is one of the most frequently asked SQL interview topics.

Frequently Asked Questions (FAQs)

1. What is the SQL BETWEEN operator?

The BETWEEN operator retrieves values that fall within a specified range.

Example:

SELECT *

FROM students

WHERE marks BETWEEN 80 AND 90;

2. Does BETWEEN include both values?

Yes.

The BETWEEN operator is inclusive, which means both the starting and ending values are included.

Example:

WHERE marks BETWEEN 80 AND 90;

This includes:

  • 80 ✅
  • 90 ✅

3. Can BETWEEN be used with text?

Yes.

Example:

SELECT *

FROM students

WHERE name BETWEEN 'A' AND 'M';

SQL compares text alphabetically.


4. Can BETWEEN be used with dates?

Yes.

Example:

SELECT *

FROM orders

WHERE order_date BETWEEN '2025-01-01' AND '2025-12-31';

This retrieves orders placed during the year 2025.


5. What is NOT BETWEEN?

NOT BETWEEN retrieves values outside the specified range.

Example:

SELECT *

FROM students

WHERE marks NOT BETWEEN 80 AND 90;

This displays students whose marks are below 80 or above 90.


6. Can BETWEEN be combined with ORDER BY?

Yes.

Example:

SELECT *

FROM students

WHERE marks BETWEEN 80 AND 95

ORDER BY marks DESC;

The query first filters records and then sorts them.


7. Where is BETWEEN used in real-world applications?

The BETWEEN operator is widely used in:

  • Student Result Analysis
  • Banking Systems
  • Employee Salary Reports
  • Sales Reports
  • Hospital Databases
  • Inventory Management
  • Business Intelligence Dashboards
  • CRM Software
  • E-commerce Applications
  • Financial Reporting

8. What is the difference between BETWEEN and IN?

BETWEEN

  • Used for continuous ranges.
  • Example:
WHERE marks BETWEEN 80 AND 90;

IN

  • Used for specific values.

Example:

WHERE marks IN (80, 85, 90);

Use BETWEEN for ranges and IN for predefined values.


Written by Shubhranshu Shekhar, who has trained 20000+ students in coding.

Scroll to Top