0
0
SQLquery~10 mins

FULL OUTER JOIN behavior in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - FULL OUTER JOIN behavior
Start with Table A and Table B
Match rows on join condition
Combine matched rows into result
Add unmatched rows from Table A with NULLs for B
Add unmatched rows from Table B with NULLs for A
Final Result Set
FULL OUTER JOIN returns all rows from both tables, matching rows where possible, and fills NULLs where no match exists.
Execution Sample
SQL
SELECT A.id, A.value, B.id, B.value
FROM A
FULL OUTER JOIN B ON A.id = B.id;
This query joins tables A and B on id, returning all rows from both tables with NULLs where no match exists.
Execution Table
StepTable A RowTable B RowJoin Condition (A.id = B.id)ActionOutput Row
1A.id=1, A.value='Apple'B.id=1, B.value='Red'TrueCombine matched rows1, 'Apple', 1, 'Red'
2A.id=2, A.value='Banana'B.id=2, B.value='Yellow'TrueCombine matched rows2, 'Banana', 2, 'Yellow'
3A.id=3, A.value='Cherry'No matching B rowFalseAdd A row with NULLs for B3, 'Cherry', NULL, NULL
4No matching A rowB.id=4, B.value='Green'FalseAdd B row with NULLs for ANULL, NULL, 4, 'Green'
5No more rowsNo more rowsN/AEnd of joinResult complete
💡 All rows from both tables processed; unmatched rows included with NULLs.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4Final
Output Rows Count012344
Key Moments - 2 Insights
Why do some columns have NULL values in the output?
Because FULL OUTER JOIN includes unmatched rows from both tables, it fills missing side columns with NULLs as shown in steps 3 and 4 of the execution_table.
Does FULL OUTER JOIN only return rows where the join condition is true?
No, it returns all rows from both tables. Matched rows are combined (steps 1 and 2), but unmatched rows from either table are also included with NULLs (steps 3 and 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output row at step 3?
ANULL, NULL, 3, 'Cherry'
B3, 'Cherry', NULL, NULL
C3, 'Cherry', 3, 'Cherry'
DNULL, NULL, NULL, NULL
💡 Hint
Check the 'Output Row' column for step 3 in the execution_table.
At which step does the join condition evaluate to False because there is no matching row in Table B?
AStep 1
BStep 4
CStep 3
DStep 2
💡 Hint
Look at the 'Join Condition' column in the execution_table for where Table B row is missing.
If Table B had an extra row with id=5, how would the output rows count change after step 4?
AIt would increase by 1
BIt would stay the same
CIt would decrease by 1
DIt would double
💡 Hint
Refer to variable_tracker for how output rows count increases with unmatched rows from Table B.
Concept Snapshot
FULL OUTER JOIN syntax:
SELECT columns
FROM A
FULL OUTER JOIN B ON A.key = B.key;

Returns all rows from A and B.
Matches rows where keys equal.
Unmatched rows show NULLs for missing side.
Full Transcript
FULL OUTER JOIN returns all rows from both tables involved in the join. It matches rows where the join condition is true and combines their columns. For rows in one table without a match in the other, it includes them with NULL values for the missing columns. This ensures no data is lost from either table. The execution steps show matching rows combined first, then unmatched rows from each table added with NULLs. The output row count increases with each added row. This join is useful when you want a complete view of both tables, including unmatched data.