SQL Server BETWEEN Condition (Operator)

The SQL Server BETWEEN operator is used to retrieve values within a specified range in a SELECT, INSERT, UPDATE, or DELETE statement.

Syntax:

expression BETWEEN value1 AND value2;  

Parameter Explanation

expression: It specifies a column or a calculation.

value1 and value2: These values specify inclusive range that is used by expression for comparison.

BETWEEN operator with Numeric Value

Retrieve all employees from table “Employees” where id is between 7 and 13.

SELECT *  

FROM [javatpoint].[dbo].[Employees]  

WHERE id BETWEEN 7 AND 13;

Output:

SQL Between condition 1

Or

    SELECT *  
    
    FROM [javatpoint].[dbo].[Employees]  
    
    WHERE id >= 7  
    
    AND id <= 13;

    Output:

    SQL Between condition 2

    BETWEEN operator with NOT Operator

    Retrieve all employees from table “Employees”, where it satisfies the following BETWEEN NOT condition.

    SELECT *  
    
    FROM [javatpoint].[dbo].[Employees]  
    
    WHERE id NOT BETWEEN 7 AND 11;

    Output:

    SQL Between condition 3

    Or

      SELECT *  
      
      FROM [javatpoint].[dbo].[Employees]  
      
      WHERE id < 7  
      
      OR id > 11;

      Output:

      SQL Between condition 4

      Comments

      Leave a Reply

      Your email address will not be published. Required fields are marked *