SQL BETWEEN Operator is used to select data from a database table based on a given range.
In this lesson we are working with the tblproduct table which includes the following fields
ProductID, Category, BrandName, ProductName, Price
BETWEEN Operator
In this example we are going to select products which are in the price range of 30000 to 70000 from the table tblproduct
The following query will select products within the given price range of 30000 to 70000.
SELECT * FROM tblproduct
WHERE Price BETWEEN 30000 AND 70000;
The output of the above query will be shown as follows
NOT BETWEEN Operator
NOT BETWEEN Operator is the opposite of the BETWEEN Operator.
In this example we are going to select the products which are not in the price range of 30000 to 70000 from the table tblproduct
The following query will select the products which are not in the price range of 30000 to 70000
SELECT * FROM tblproduct
WHERE Price NOT BETWEEN 30000 AND 70000;
The output of the above query will be shown as follows