SQL BETWEEN Operator – SQL TUTORIAL | Software Testing Material

SQL BETWEEN Operator:

SQL BETWEEN operator selects values within a range. The values can be numbers, text, or dates.

SQL BETWEEN Syntax:

1
SELECT column_name(s) FROM table_name WHERE column_name BETWEEN value_1 AND value_2;

SQL BETWEEN Example:

1
2
SELECT * FROM SCOREBOARD WHERE Runs BETWEEN 90 AND 100;
SELECT * FROM SCOREBOARD WHERE Runs BETWEEN 20 AND 100;

In the below image, you could find three SELECT queries. First SELECT query returns complete records from the table SCOREBOARD where as other two SELECT queries returns based on WHERE Clause.

In the second and third SELECT query, we took BETWEEN Operator.

Second query returns the values where values in the Runs column are between 90 and 100 and the third query returns where the values in the Runs column are between 20 and 100.

SQL NOT BETWEEN Operator:

Syntax:

1
SELECT * FROM Table_Name WHERE SomeColumn_Name NOT BETWEEN ‘Some_Value’ AND ‘Some_Value’;

 Example:

1
SELECT * FROM SCOREBOARD WHERE Runs NOT BETWEEN 90 AND 100;

In the below image, you could find three SELECT queries. First SELECT query returns complete records from the table SCOREBOARD where as other two SELECT queries returns based on WHERE Clause.

In the second and third SELECT query, we took BETWEEN Operator.

Second query returns the values where values in the Runs column are not between 90 and 100 and the third query returns where the values in the Runs column are not between 20 and 100.

In the next tutorial, we will see How To Use AND OR OPERATOR in SQL

Check out the complete SQL Tutorial by clicking on below link:

SQL Tutorial – Complete