In this article, we will learn how to use the BETWEEN operator with a SQL select query.
The BETWEEN operator is used to select values within a given range, begin and end values are also included in that. The values can be numbers, strings, or dates.
Syntax
SELECT column_name(s) FROM TABLE_NAME WHERE column_name BETWEEN value1 AND value2;
Example-1
The subsequent statement would return all articles with an ID BETWEEN 3 AND 7.
SELECT * FROM Article WHERE ID BETWEEN 3 AND 7;
Example-2
The subsequent statement would return all articles without an ID BETWEEN 3 AND 7.
SELECT * FROM Article WHERE ID NOT BETWEEN 3 AND 7;
Also, check How To Use IN, NOT IN Operator In SQL