Italian Trulli

SQL Between Operator With Example

Test Tribe
.

Between Operator in SQL - SQL Between Operator

Between operators in SQL with example


SQL Between Operator

In SQL Between operator is used to select values within a given range. The values can be numbers, text, or dates. It can be used in a SELECT, INSERT, UPDATE, or DELETE statement.

Syntax of Between Operator 
The basic syntax of between operators is given below.

SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value1 AND value2;

Example of Between Operator
The basic example of between operators is given below. 

Example of Between Operator 

Consider the above employee table.

SELECT EmployeeName FROM Employee WHERE Salary BETWEEN 25000 AND 45000;

Example Explanation:
The above SQL query will return all the employees who are having salaries between 25000 and 45000

How to Use Between Operator In SQL 

How to Use Between Operator 


Between Operator with Numeric Values 

How to use BETWEEN operator with Numeric Value?

Requirement: We have to find out the employees who is having salaries between 25000 and 45000.(Check the above table)

Consider the above employee table. 

SELECT EmployeeName FROM Employee WHERE Salary BETWEEN 25000 AND 45000;

Example Explanation:
The above SQL query will return all the employees who is having salaries between 25000 and 45000.

Between Operator with NOT

How to use BETWEEN operator with NOT?

Requirement: We have to find out the employees who is having salaries, not between 40000 and 45000.(Check the above table)

Consider the above employee table. 

SELECT EmployeeName FROM Employee WHERE Salary NOT BETWEEN 25000 AND 45000;

Example Explanation:
The above SQL query will return all the employees who have salaries not, between 40000 and 45000.

Between Operator with Date

How to use the BETWEEN operator with Date?

Requirement: We have to find out the employees who have DOB between 01-20-1995 and 01-20-1999.(Check the above table)

Consider the above employee table.
 
SELECT EmployeeName FROM Employee WHERE DOB BETWEEN '01-20-1995' and '01-20-1999';

Example Explanation:
The above SQL query will return all the employees who is having DOB between 01-20-1995 and 01-20-1999.

Between Operator with Text Values

How to use the BETWEEN operator with Text values?

Requirement: We have to find out the employees who have Names between Sandeep Yadav and Shyam.(Check the above table)

SELECT EmployeeName FROM Employee WHERE EmployeeName BETWEEN 'Sandeep Yadav' and 'Shyam';

Between Operator with IN Operator

How do you use the BETWEEN operator with the IN Operator?

Requirement: We have to find out the employees who have Names between Sandeep Yadav and Shyam.do not show the employee name with salary 25000, 35000, 42000. (Check the above table)

SELECT EmployeeName FROM Employee WHERE EmployeeName BETWEEN 'Sandeep Yadav' and 'Shyam' AND salary NOT IN (25000, 35000, 42000);

Hope !!! The above tutorial on "SQL Between Operator With Example" is helpful for you...

Team,
QA acharya

Post a Comment

0 Comments