0
0
SQLquery~10 mins

WHERE with comparison operators in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - WHERE with comparison operators
Start Query
Read FROM table
Apply WHERE condition
Evaluate comparison operator
Row matches?
Include row
Return filtered rows
End Query
The query reads the table, applies the WHERE condition using comparison operators to each row, includes rows that match, excludes others, and returns the filtered result.
Execution Sample
SQL
SELECT * FROM employees WHERE salary > 50000;
This query selects all employees whose salary is greater than 50000.
Execution Table
StepRow IDsalaryCondition (salary > 50000)Include Row?
114800048000 > 50000 = FalseNo
225200052000 > 50000 = TrueYes
335000050000 > 50000 = FalseNo
447500075000 > 50000 = TrueYes
553000030000 > 50000 = FalseNo
666000060000 > 50000 = TrueYes
Exit--No more rows to check-
💡 All rows checked; query returns only rows where salary > 50000 is True.
Variable Tracker
VariableStartAfter Row 1After Row 2After Row 3After Row 4After Row 5After Row 6Final
Current Row ID-123456-
Condition Result-FalseTrueFalseTrueFalseTrue-
Included Rows[][][2][2][2,4][2,4][2,4][2,4,6]
Key Moments - 2 Insights
Why is the row with salary 50000 not included even though it equals 50000?
Because the condition uses '>' (greater than), which excludes values equal to 50000. Only values strictly greater than 50000 pass, as shown in execution_table rows 3 and 4.
What happens if the condition is false for a row?
The row is excluded from the result. For example, row 1 with salary 48000 fails the condition and is not included, as seen in execution_table step 1.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, which row is the first to be included in the result?
ARow 1
BRow 2
CRow 3
DRow 5
💡 Hint
Check the 'Include Row?' column in execution_table for the first 'Yes'.
At which step does the condition 'salary > 50000' become false for the first time?
AStep 1
BStep 2
CStep 3
DStep 4
💡 Hint
Look at the 'Condition (salary > 50000)' column in execution_table for the first 'False'.
If the condition changed to 'salary >= 50000', which row would be included that was previously excluded?
ARow with salary 48000
BRow with salary 30000
CRow with salary 50000
DRow with salary 60000
💡 Hint
Check which row had salary exactly 50000 and was excluded before in execution_table.
Concept Snapshot
WHERE clause filters rows using comparison operators.
Syntax: WHERE column operator value
Common operators: =, >, <, >=, <=, <>
Only rows meeting the condition are returned.
Comparison is done row by row.
Full Transcript
This visual execution shows how the SQL WHERE clause works with comparison operators. The query reads each row from the employees table and checks if the salary is greater than 50000. For each row, the condition is evaluated: if true, the row is included in the result; if false, it is excluded. The execution table lists each row's salary, the condition result, and whether the row is included. The variable tracker shows how the current row and included rows change step by step. Key moments clarify why equal values are excluded with '>' and what happens when the condition is false. The quiz tests understanding by asking about specific steps and effects of changing the condition. This helps beginners see exactly how filtering works in SQL queries.