×

SQL SELECT BETWEEN Operator

This SQL tutorial explains and helps us understand how to use the BETWEEN operator in the SELECT query with examples.

The SQL SELECT BETWEEN operator retrieves the data from the table where the values are within the specified expression. The BETWEEN operator range starts with the starting value followed by AND operator and the ending value. The range values can be numeric, string, or dates

The syntax of the SQL SELECT BETWEEN Operator is as follows:

SELECT Column_Name_1, Column_Name_2, Column_Name_3, Column_Name_4, Column_Name_5 FROM Table_Name WHERE Column_Name BETWEEN starting_value AND ending_value;

Let’s understand the SQL SELECT BETWEEN Operator with the help of examples.

Consider the already existing table, which has the following data:

Table Name:- D_Students

Student_IdStudent_NameFirst_SemSecond_SemThird_SemFourth_SemFifth_SemSixth_SemTotalDepartment_Id
202111Vaishnavi Patil949188859592911
202112Vaibhav Lokhande859092808582862
202113Yash Dhull908894878590893
202114Sonali Patole959092889290914
202115Axar Patel858082869284851
202116Meena Mishra787580748577783
202117Mahesh Kumbhar758075788076775
202118Sakshi Patil807874788077782
202119Sopan Bhore706875758080752
202220Prajwal Lokhande808585757880814
202221Anuja Wanare858886828485855
202222Venkatesh Iyer908987909291903
202223Anushka Sen707571748078751
202224Aakash Jain807572748580784
202225Akshay Agarwal858078889082845
202226Shwetali Bhagwat908085889080861
202227Mayuri Wagh808085808285824
202228Utkarsh Rokade858080908484845
202229Manthan Koli857584788280812
202230Mayur Jain808887909290881

Example 1: Execute a query to display student's information where the student's first-semester percentage is between 80 and 90.

SELECT * FROM D_Students WHERE First_Sem BETWEEN 80 AND 90;

We fetched the student's information from the D_Students table, where the student's first-semester percentage is between 80 and 90 in the above query.

The output of the above query is as follows:

Student_IdStudent_NameFirst_SemSecond_SemThird_SemFourth_SemFifth_SemSixth_SemTotalDepartment_Id
202112Vaibhav Lokhande859092808582862
202113Yash Dhull908894878590893
202115Axar Patel858082869284851
202118Sakshi Patil807874788077782
202220Prajwal Lokhande808585757880814
202221Anuja Wanare858886828485855
202222Venkatesh Iyer908987909291903
202224Aakash Jain807572748580784
202225Akshay Agarwal858078889082845
202226Shwetali Bhagwat908085889080861
202227Mayuri Wagh808085808285824
202228Utkarsh Rokade858080908484845
202229Manthan Koli857584788280812
202230Mayur Jain808887909290881
SQL SELECT BETWEEN Operator

Example 2: Execute a query to display student’s information where student name between 'Aakash Jain' AND 'Shwetali Bhagwat'.

SELECT * FROM D_Students WHERE Student_Name BETWEEN 'Aakash Jain' AND 'Shwetali Bhagwat';

We retrieved the student's information from the D_Students table where the student's name is between 'Aakash Jain' AND 'Shwetali Bhagwat' in the above query.

The output of the above query is as follows:

Student_IdStudent_NameFirst_SemSecond_SemThird_SemFourth_SemFifth_SemSixth_SemTotalDepartment_Id
202115Axar Patel858082869284851
202116Meena Mishra787580748577783
202117Mahesh Kumbhar758075788076775
202118Sakshi Patil807874788077782
202220Prajwal Lokhande808585757880814
202221Anuja Wanare858886828485855
202223Anushka Sen707571748078751
202224Aakash Jain807572748580784
202225Akshay Agarwal858078889082845
202226Shwetali Bhagwat908085889080861
202227Mayuri Wagh808085808285824
202229Manthan Koli857584788280812
202230Mayur Jain808887909290881
SQL SELECT BETWEEN Operator

Example 3: Execute a query to display student's information where the student's fifth-semester percentage is between 75 and 95, AND the department name is Computer, Mechanical, and Civil Engineering.

SELECT * FROM D_Students WHERE Fifth_Sem BETWEEN 75 and 95 AND Department_Id IN (SELECT Department_Id FROM Department WHERE Department_Name IN ('Computer Engineering', 'Mechanical Engineering', 'Civil Engineering'));

We displayed the student's information where the fifth-semester percentage is between 75 and 95. The student's department names are Computer, Mechanical, and Civil Engineering, and the records are displayed in ascending order.

The output of the above query is as follows:

Student_IdStudent_NameFirst_SemSecond_SemThird_SemFourth_SemFifth_SemSixth_SemTotalDepartment_Id
202111Vaishnavi Patil949188859592911
202115Axar Patel858082869284851
202223Anushka Sen707571748078751
202226Shwetali Bhagwat908085889080861
202230Mayur Jain808887909290881
202113Yash Dhull908894878590893
202116Meena Mishra787580748577783
202222Venkatesh Iyer908987909291903
202117Mahesh Kumbhar758075788076775
202221Anuja Wanare858886828485855
202225Akshay Agarwal858078889082845
202228Utkarsh Rokade858080908484845
SQL SELECT BETWEEN Operator

Related Topics

How to use LIKE in SQL

In this SQL article, we will learn and understand how to use LIKE to the columns in the SQL tables. What is Like? Like is an operator in the SQL. It is...

7 minutes read.

Commit and Rollback in SQL

In Structured Query Language, we have Data Definition Language (DDL) and Data Manipulation Language (DML) commands the same way we have Transaction Control Language (TCL) commands in the Structured Query...

4 minutes read.

SQL Comparision Operator

The Comparison Operator compares different data of the Structured Query Language table and checks whether the data are the same, less than, greater than, less than, or greater than equal....

14 minutes read.

SQL INTERSECT

SQL intersect operator is used to combine two or more SELECT statements, but it only displays the data similar to the SELECT statement. The syntax for the INTERSECT operation: SELECT COLUMN_NAME1, COLUMN_NAME2,...

3 minutes read.

SQL SELECT AVG

In this tutorial, we will learn about the aggregate function name avg() function concept in SQL with the help of examples. The AVG() function is one of the aggregate functions in...

3 minutes read.

SQL DROP Database

This tutorial will help us understand how to drop a database from the SQL Server with a few examples. The DROP command removes all the objects stored in the database and...

4 minutes read.

SQL Wildcards

SQL WILDCARD CHARACTERS: SQL wild card character is used to substitute zero or more characters of a string. These characters are used with the “LIKE” operator. Wild Card Characters in SQL: %_[]^- “%” : It is...

3 minutes read.

SQL Aliases

SQL Aliases: These are used to give a temporary name for a column or table. These are used to make tables or columns more readable. These are used to rename the table...

2 minutes read.

Drop vs Truncate in SQL

In this article, we will learn and understand the Drop and Truncate commands and the difference between these two commands. What is Drop Command? Drop is a Data Definition Language command in...

6 minutes read.

How to delete a row in SQL

Introduction To delete or remove the unused/unwanted rows from a table, DELETE command is used in SQL.DELETE command removes the entire record from a table.The DELETE statement can delete one or...

6 minutes read.

How to compare date in SQL

In this section, we will learn about how dates can be compared in SQL. We can compare any random date with another date stored in a column of a table.This comparison...

4 minutes read.

SQL WHERE Clause

The WHERE clause is a search filter that returns only true records. The WHERE clause chooses the selected records based on the given conditions. The WHERE clause is used with...

4 minutes read.

WHERE Clause vs HAVING Clause

The WHERE Clause and HAVING clause filter the records in the Structured Query Language queries. The main difference between the WHERE clause and the HAVING clause is the WHERE clause...

5 minutes read.

SQL Scalar Functions

TEACHER Table LCASE() Function The LCASE() function is used to return lower case values of specified column. Syntax: Select Lcase(column_name) from table_name; Example: Select Lcase(teacher_name) from teacher; Syntax: Select Lcase(column_name) from table_name [where condition]; Example: Select Lcase(teacher_name) from teacher where teacher_id=1; UCASE() Function The UCASE()...

1 minute read.

How to delete column in table

Introduction In SQL, sometimes it is required to delete a column of a table.The use of ALTER TABLE command with DROP COLUMN clause will serve the purpose to delete/remove a column...

4 minutes read.

WEB SQL

What is Web SQL? In SQL we can create databases, read the data in the databases, insert the records into the databases, and delete the records from the databases. For storing...

4 minutes read.

Truncate function in SQL

The TRUNCATE is a numeric function in SQL which truncates the number according to the particular decimal points. Syntax of TRUNCATE Function SELECT TRUNCATE(X, D) AS Alias_Name; In the TRUNCATE syntax, X...

4 minutes read.

SQL Arithmetic Operators

This page contains all the information, learn about SQL Arithmetic Operators concept in the SQL table with the help of examples. The Arithmetic Operators is used to perform mathematical calculations on...

5 minutes read.

Types of SQL Commands

The Structured Query Language is used to deal with structured data. The data which are stored in the form of tables are structured data. These SQL commands store records or...

10 minutes read.

SQL CROSS Join

In this tutorial, we will help you understand the concept of the SQL CROSS Join clause with the few examples. The SQL CROSS Join query is used to join one or...

5 minutes read.