SQL -Structured Query Language - Sql Clause - Between & Not Between Operator Tutorial
BETWEEN OPERATOR
To retrieve the record within the given range based on the number, text, or date. Then we can use a ' WHERE ' statement with BETWEEN Operator.
For example, suppose we want to retrieve a record whose date lies between 01-01-2019 AND 01-01-2020.
Then we can use the date as a column and use BETWEEN operator.
Syntax-
The basic syntax of the WHERE statement with BETWEEN operator is.–
SELECT * FROM table_name
WHERE
column_name
BETWEEN value_1 AND value_2;
In this, it will retrieve the record where its column_name value is BETWEEN value_1 and value_2.
For example –
SELECT * FROM job_history
WHERE
start_date
BETWEEN '1993-01-01' AND '1997-01-01';
In this statement, it will retrieve the records whose start_date BETWEEN '1993-01-01' AND '1997-01-01' from the job_history table.
NOT BETWEEN OPERATOR
To retrieve the record, not in the given range based on the number, text, or date. Then we can use a ' WHERE ' statement with NOT BETWEEN Operator.
For example, suppose we want to retrieve a record whose date not lies between 01-01-2019 AND 01-01-2020.
Then we can use the date as a column and use the NOT BETWEEN operator.
Syntax-
The basic syntax of the WHERE statement with NOT BETWEEN operator is.–
SELECT * FROM table_name
WHERE
column_name
NOT BETWEEN value_1 AND value_2;
In this, it will retrieve the record where its column_name value is NOT BETWEEN value_1 and value_2.
For example –
SELECT * FROM job_history
WHERE
start_date
NOT BETWEEN '1993-01-01' AND '1997-01-01';
In this statement, it will retrieve the records whose start_date NOT BETWEEN '1993-01-01' AND '1997-01-01' from the job_history table.