The SQL BETWEEN operator is used to fetch records between a given range.
Let’s say, we want to retrieve all books within a given prince range $90 to $400 from a BOOKS table.
Another example we can take as we want to list all employees whose salary is between $5000 to $10000. or whose age is between 40 to 50 etc.
- BETWEEN condition is used to retrieve values within a range.
- The range consists of begin value followed by AND keyword and end value.
- The operator returns true when the search value present within the range, others returns false.
SQL BETWEEN Operator Syntax
SELECT [column_name] FROM [TABLE_NAME]
WHERE [COLUMN_NAME] BETWEEN [value_from ] AND [value_to];
Find all the books between the price range 90 and 400 from books table.
SQL query for this is very simple. Just find the range in PRICE column of the BOOKS table between the given range using SQL AND Operator
SELECT TITLE FROM BOOKS WHERE PRICE BETWEEN 90 AND 400;