BETWEEN in SQL

HOW TO USE BETWEEN OPERATOR IN SQL?

BETWEEN operator fetches the records from the table within the range specified in the query. Between Operator includes the starting and ending values of the specified range.

Syntax of BETWEEN in SQL-

SELECT(ColumnName(s))

FROM <TableName>

WHERE<ColumnName>

BETWEEN value1 AND value2;  

Example of BETWEEN in SQL-

SELECT *

FROM Products

WHERE Price

BETWEEN 18 AND 22; 

โ€“It will select all the products with a price between 18 to 22.

NOT BETWEEN operator fetches the records from the table outside the range specified in the query.

Syntax of NOT BETWEEN in SQL-

SELECT(ColumnName(s))

FROM <TableName>

WHERE<ColumnName>

NOT BETWEEN value1 AND value2;  

Example of NOT BETWEEN in SQL-

SELECT *

FROM Products

WHERE Price

NOT BETWEEN 18 AND 22; 

โ€“It will select all the products with a price not between 18 to 22.

Note-

Northwind sample database is used for example.


Posted

in

Tags:

Comments

Leave a Reply