0
0
PostgreSQLquery~10 mins

BETWEEN for range filtering in PostgreSQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - BETWEEN for range filtering
Start Query
Check BETWEEN condition
Include row
Return filtered rows
End
The query checks each row to see if a value falls within a range using BETWEEN. Rows that satisfy the condition are included in the result.
Execution Sample
PostgreSQL
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? FALSENo
221010 BETWEEN 10 AND 20? TRUEYes
331515 BETWEEN 10 AND 20? TRUEYes
442020 BETWEEN 10 AND 20? TRUEYes
552525 BETWEEN 10 AND 20? 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?
Yes, as shown in execution_table rows 2 and 4, prices exactly 10 and 20 are included because BETWEEN is inclusive.
What happens if the value is less than the lower bound?
As in row 1, price 5 is less than 10, so the condition is false and the row is excluded.
Is BETWEEN equivalent to using >= and <=?
Yes, price BETWEEN 10 AND 20 is the same as price >= 10 AND price <= 20, including boundaries.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the Include Row? value for Row ID 3?
ANo
BMaybe
CYes
DNot checked
💡 Hint
Check the row with Row ID 3 in the execution_table under Include Row? column.
At which step does the condition first become TRUE?
AStep 1
BStep 2
CStep 5
DStep 6
💡 Hint
Look at the Condition column in execution_table to find the first TRUE.
If the BETWEEN range changed to 15 AND 25, which row would now be included that was previously excluded?
ARow ID 5
BRow ID 2
CRow ID 1
DRow ID 3
💡 Hint
Check the price values and see which row's price falls between 15 and 25 but was excluded before.
Concept Snapshot
BETWEEN syntax: value BETWEEN low AND high
Includes values from low to high, inclusive.
Equivalent to value >= low AND value <= high.
Used for filtering rows within a range.
Easy way to check if a value falls inside a range.
Full Transcript
This visual execution shows how the SQL BETWEEN operator filters rows by checking if a value lies within a specified range. Each row's price is tested against the condition price BETWEEN 10 AND 20. Rows with prices 10, 15, and 20 satisfy the condition and are included in the result. Rows with prices outside this range are excluded. BETWEEN includes the boundary values, making it equivalent to using >= and <= together. This step-by-step trace helps beginners see how each row is evaluated and understand the inclusive nature of BETWEEN.