0
0
SQLquery~10 mins

WHERE with AND operator in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - WHERE with AND operator
Start Query
Scan Table Rows
Evaluate Condition 1
Evaluate Condition 2
Condition 1 AND Condition 2?
Yes No
Include Row
Return Filtered Rows
End
The query scans each row, checks both conditions joined by AND, includes the row only if both are true, then returns all such rows.
Execution Sample
SQL
SELECT * FROM Employees
WHERE Department = 'Sales' AND Salary > 50000;
This query selects employees who work in Sales and earn more than 50000.
Execution Table
StepRow DataCondition 1: Department='Sales'Condition 2: Salary>50000AND ResultAction
1{ID:1, Dept:'Sales', Salary:65000}TrueTrueTrueInclude Row
2{ID:2, Dept:'Sales', Salary:45000}TrueFalseFalseSkip Row
3{ID:3, Dept:'HR', Salary:70000}FalseTrueFalseSkip Row
4{ID:4, Dept:'Sales', Salary:52000}TrueTrueTrueInclude Row
5{ID:5, Dept:'IT', Salary:48000}FalseFalseFalseSkip Row
6No more rows---End of scan
💡 All rows scanned; only rows where both conditions are true are included.
Variable Tracker
VariableStartAfter Row 1After Row 2After Row 3After Row 4After Row 5Final
Current RowNone{ID:1, Dept:'Sales', Salary:65000}{ID:2, Dept:'Sales', Salary:45000}{ID:3, Dept:'HR', Salary:70000}{ID:4, Dept:'Sales', Salary:52000}{ID:5, Dept:'IT', Salary:48000}None
Condition 1 ResultN/ATrueTrueFalseTrueFalseN/A
Condition 2 ResultN/ATrueFalseTrueTrueFalseN/A
AND ResultN/ATrueFalseFalseTrueFalseN/A
Rows Included[][{ID:1,...}][{ID:1,...}][{ID:1,...}][{ID:1,...},{ID:4,...}][{ID:1,...},{ID:4,...}][{ID:1,...},{ID:4,...}]
Key Moments - 2 Insights
Why is a row skipped even if one condition is true?
Because the AND operator requires both conditions to be true. For example, in step 2, Department='Sales' is true but Salary>50000 is false, so the row is skipped.
What happens if both conditions are false?
The row is skipped since AND needs both true. See step 5 where both conditions are false, so the row is not included.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the AND result at step 3?
AUnknown
BTrue
CFalse
DError
💡 Hint
Check the 'AND Result' column at step 3 in the execution_table.
At which step does the condition Department='Sales' become false?
AStep 3
BStep 2
CStep 4
DStep 5
💡 Hint
Look at the 'Condition 1' column in the execution_table for false values.
If Salary condition changed to Salary > 60000, which step's AND result would change from True to False?
AStep 1
BStep 4
CStep 5
DStep 2
💡 Hint
Compare Salary values at steps 1 and 4 with new condition >60000.
Concept Snapshot
WHERE clause filters rows based on conditions.
AND operator requires all conditions to be true.
Each row is checked: if all true, row included.
If any condition false, row skipped.
Useful to combine multiple filters in queries.
Full Transcript
This visual execution shows how the SQL WHERE clause with AND operator works. The query scans each row of the Employees table. For each row, it checks if the Department is 'Sales' and if the Salary is greater than 50000. Only rows where both conditions are true are included in the result. The execution table traces each row's data, condition results, and final decision to include or skip. The variable tracker shows how conditions and included rows change step by step. Key moments clarify why rows are skipped if any condition fails. The quiz tests understanding of condition evaluation and AND logic. This helps beginners see exactly how AND filters data in SQL queries.