SQL BETWEEN Operator - The Coding Shala

Home >> Learn SQL >> SQL Between Operator

SQL BETWEEN Operator

The SQL 'BETWEEN' Operator is used to select values within the given range. These values can be numbers, texts or dates.  In SQL 'BETWEEN' Operator begin and end values are included.
SQL BETWEEN Operator - The Coding Shala

SQL BETWEEN Operator Syntax

The basic syntax of SQL BETWEEN Operator is as follows - 

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

SQL BETWEEN Operator Example

The following 'emp' table is used for the examples - 

 Id     Name     Age     Address     Salary  
 1     Akshay     22     Pune        40000  
 2     Mohit      21     Delhi       42000  
 3     Akash      21     Delhi       45000  
 4     Nikhil     24     Mumbai      50000  
 5     Smith      24     Pune        50000  
 6     Akshay     22     Pune        50000  
 7     Nikhil     24     Mumbai      43000  

The following query will return records where Age is between 22 to 24 - 

 SQL >> select * from emp  
        where Age between 22 and 24;  
 
Output >>   
 Id     Name     Age     Address     Salary  
 1     Akshay     22     Pune       40000  
 4     Nikhil     24     Mumbai     50000  
 5     Smith      24     Pune       50000  
 6     Akshay     22     Pune       50000  
 7     Nikhil     24     Mumbai     43000  



Other Posts You May Like
Prev<< SQL IN Operator                                                        NEXT >>SQL min() and max() function
Please leave a comment below if you like this post or found some error, it will help me to improve my content.

Comments

Popular Posts from this Blog

Java Program to Convert Binary to Decimal - The Coding Shala

N-th Tribonacci Number Solution - The Coding Shala

Shell Script to find sum, product and average of given numbers - The Coding Shala

Shell Script to Create a Simple Calculator - The Coding Shala

Java Program to Convert Decimal to Binary - The Coding Shala