0
0
SQLquery~10 mins

LEFT JOIN execution behavior in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - LEFT JOIN execution behavior
Start with Left Table
For each row in Left Table
Find matching rows in Right Table
Yes No
Combine rows
Add combined row to result
Repeat for next Left row
End
The LEFT JOIN goes through each row in the left table, tries to find matching rows in the right table, and combines them. If no match is found, it fills the right side with NULLs and still includes the left row.
Execution Sample
SQL
SELECT A.id, A.name, B.score
FROM Students A
LEFT JOIN Scores B ON A.id = B.student_id;
This query lists all students and their scores if available; if no score exists, it shows NULL.
Execution Table
StepLeft Table RowMatching Right Rows Found?ActionOutput Row
1id=1, name='Alice'Yes (score=85)Combine left and right rows1, 'Alice', 85
2id=2, name='Bob'NoCombine left row with NULLs for right2, 'Bob', NULL
3id=3, name='Charlie'Yes (score=92)Combine left and right rows3, 'Charlie', 92
4id=4, name='Diana'NoCombine left row with NULLs for right4, 'Diana', NULL
5No more rowsN/AStop executionEnd of result set
💡 All rows from left table processed; query ends.
Variable Tracker
VariableStartAfter 1After 2After 3After 4Final
Current Left RowNoneid=1, name='Alice'id=2, name='Bob'id=3, name='Charlie'id=4, name='Diana'None
Matching Right RowsNonescore=85Nonescore=92NoneNone
Output Rows Count012344
Key Moments - 2 Insights
Why do some rows have NULL values in the right table columns?
When no matching row is found in the right table for a left table row, the right side columns are filled with NULLs to keep the left row in the result (see execution_table rows 2 and 4).
Does LEFT JOIN exclude any rows from the left table?
No, LEFT JOIN always includes all rows from the left table regardless of matches in the right table, as shown by all left rows appearing in the output (execution_table all steps).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the output row at step 2?
A2, 'Bob', 85
BNULL, NULL, NULL
C2, 'Bob', NULL
D2, 'Bob', 92
💡 Hint
Check the 'Output Row' column at step 2 in the execution_table.
At which step does the LEFT JOIN find no matching right table row for the left row?
AStep 1
BStep 2
CStep 3
DStep 5
💡 Hint
Look at the 'Matching Right Rows Found?' column in the execution_table.
If the right table had a matching row for 'Diana', how would the output change at step 4?
AOutput row would include Diana's score instead of NULL
BOutput row would be removed
COutput row would have NULLs on both sides
DNo change, still NULL for right columns
💡 Hint
Refer to how matched rows are combined in execution_table steps 1 and 3.
Concept Snapshot
LEFT JOIN syntax:
SELECT columns FROM LeftTable
LEFT JOIN RightTable ON condition;

Behavior:
- Includes all rows from LeftTable
- Matches rows from RightTable if condition met
- If no match, RightTable columns are NULL

Use to keep all left rows with optional right data.
Full Transcript
The LEFT JOIN starts by taking each row from the left table. For each left row, it looks for matching rows in the right table based on the join condition. If it finds matches, it combines the left and right rows into one output row. If no match is found, it still outputs the left row but fills the right side columns with NULL values. This process repeats for every row in the left table until all are processed. The result is a table that always includes all rows from the left table, with matching data from the right table when available, or NULLs otherwise.