SQL Between

SQL BETWEEN 

In this tutorial, you will learn how to use SQL Between operator in SQL Server

sql between

The SQL BETWEEN operator is a logical operator that allows to fetched the certain range in the specified table.



  
SELECT 
  column_name
FROM
  table_name
WHERE 
  column_name BETWEEN Start_value AND End_value;
  
  


  • First, use the select keyword and specify the column name or use * get full table data. 
  • second, mention the table name and place the start_value and End_value between the Between keyword have the same data type.
  • Here, the condition that is using Between operator that uses the operators >=, <=, AND, IN. 
  • AND used Between operator, not Between operator.

we already create the student table from the sample database
 
student table id (primary key), student_name, class, age, phone_no,


BETWEEN

 
  
SELECT 
  student_name,
  class,
  age 
FROM
  student 
WHERE age BETWEEN 15 and 16;  
  
  

SQL Between




NOT BETWEEN

  
  
SELECT 
  student_name,
  class,
  age 
FROM 
  student 
where age NOT BETWEEN 15 and 16;
  
  

SQL Between




BETWEEN ORDER BY

 
  
SELECT 
     * 
FROM
   student 
WHERE
   age BETWEEN 15 AND 16 
ORDER BY 
   student_name;  
  
  

SQL Between




NOT BETWEEN ORDER BY

  
  
SELECT 
    * 
FROM 
   student 
WHERE
   age NOT between 15 and 16 
ORDER BY 
   student_name;
  
  
  

SQL Between




BETWEEN NOT IN

  
  
SELECT 
   * 
FROM 
   student 
WHERE 
   age BETWEEN 15 AND 17  
AND id NOT IN (101,108); 
  
  

SQL Between



Previous Post Next Post