SQL - Structured Query Language

BETWEEN ... AND Operator



BETWEEN … AND operator is used to find out collection of records from group of records based on specific range of data values. The range data values may be in number, string and date data format. The characters, strings and dates data values must be define with single quotes. The following queries are used to find out collection of records from PRODUCT table based on particular range of data values.

-- Example 48 --

 

SELECT * FROM Product WHERE Prod_Tax BETWEEN 10 AND 15

 

SELECT * FROM Product WHERE Prod_Code BETWEEN 'PROD1' AND 'PROD3'

 

SELECT * FROM Product WHERE Exp_Date BETWEEN '12/01/2007' AND '12/31/2007'


Query Output Screen



Note: Instead of BETWEEN ... AND we can write a query with Greater Than (>) and Less Than (<) operator. Any BETWEEN ... AND predicate is NULL, the result is UNKNOWN. Try to avoid BETWEEN ... AND operator, while the filter column stores NULL data values.

* * * * *


Email Your Comment To AUTHOR