0
0
SQLquery~10 mins

WHERE with BETWEEN range in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - WHERE with BETWEEN range
Start Query
Read WHERE clause
Check if value BETWEEN low AND high
Include row
Return filtered rows
End
The query checks each row's value to see if it falls within the specified range using BETWEEN. Rows inside the range are included; others are excluded.
Execution Sample
SQL
SELECT * FROM products
WHERE price BETWEEN 10 AND 20;
This query selects all products with prices from 10 to 20 inclusive.
Execution Table
StepRow IDpriceCondition: price BETWEEN 10 AND 20Include Row?
1155 BETWEEN 10 AND 20 is FalseNo
221010 BETWEEN 10 AND 20 is TrueYes
331515 BETWEEN 10 AND 20 is TrueYes
442020 BETWEEN 10 AND 20 is TrueYes
552525 BETWEEN 10 AND 20 is FalseNo
6EndQuery ends, all rows checked
💡 All rows checked; rows with price between 10 and 20 inclusive are included.
Variable Tracker
VariableStartAfter Row 1After Row 2After Row 3After Row 4After Row 5Final
priceN/A510152025N/A
Include Row?N/ANoYesYesYesNoN/A
Key Moments - 3 Insights
Does BETWEEN include the boundary values (low and high)?
Yes, BETWEEN includes both the low and high values as shown in rows 2 and 4 where price equals 10 and 20 and rows are included.
What happens if the value is less than the low boundary?
The row is excluded, as shown in row 1 where price is 5, which is less than 10, so it is not included.
Is BETWEEN equivalent to using >= low AND <= high?
Yes, BETWEEN low AND high is the same as checking if value >= low AND value <= high, filtering rows inclusively.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, is the row with price 20 included or excluded?
ADepends on other conditions
BExcluded
CIncluded
DNot checked
💡 Hint
Check row 4 in the execution_table where price is 20 and see the Include Row? column.
At which step does the condition first become true?
AStep 1
BStep 2
CStep 5
DStep 3
💡 Hint
Look at the Condition column in execution_table and find the first 'True' result.
If the BETWEEN range changed to BETWEEN 15 AND 25, which row would now be excluded?
ARow with price 10
BRow with price 15
CRow with price 20
DRow with price 25
💡 Hint
Compare the original range 10-20 with the new range 15-25 and see which price falls outside.
Concept Snapshot
WHERE with BETWEEN range:
- Syntax: WHERE column BETWEEN low AND high
- Includes rows where column >= low AND column <= high
- Boundaries are inclusive
- Filters rows within the specified range
- Simplifies range conditions in queries
Full Transcript
This visual execution shows how the SQL WHERE clause with BETWEEN works. Each row's price is checked to see if it falls between 10 and 20 inclusive. Rows with prices 10, 15, and 20 pass the condition and are included in the result. Rows with prices outside this range are excluded. BETWEEN includes the boundary values. This is equivalent to using >= and <= conditions combined.