The BETWEEN clause is used to display the value that falls within a specified range of values.
Also can explain that The BETWEEN condition allows you to retrieve values within a range
The syntax for the BETWEEN clause is:
SELECT [COLUMN NAME] FROM [TABLE NAME]
WHERE[COLUMN 1] BETWEEN [LOWER VALUE] AND [UPPER VALUE]
EXAMPLE :
For Example, we like to call out player name that scores is between 2000 to 2500.
Table GameScores
PlayerName | Department | Scores |
Jason | IT | 3000 |
Irene | IT | 1500 |
Jane | Marketing | 1000 |
David | Marketing | 2500 |
Paul | HR | 2000 |
James | HR | 2000 |
SQL statement :
SELECT PlayerName FROM GameScores
WHERE Scores BETWEEN 2000 AND 2500
Result:
PlayerName |
David |
Paul |
James |
NOT clause also can be use in BETWEEN clause to get the data not within a range.
The syntax for the BETWEEN clause is:
SELECT [COLUMN NAME] FROM [TABLE NAME]
WHERE[COLUMN 1] NOT BETWEEN [LOWER VALUE] AND [UPPER VALUE]
SQL statement :
SELECT PlayerName FROM GameScores
WHERE Scores NOT BETWEEN 2000 AND 2500
Result:
PlayerName |
Jason |
Irene |
Jane |