0
0
SQLquery~10 mins

INNER JOIN with ON condition in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - INNER JOIN with ON condition
Start with Table A
Apply ON condition
Match rows where ON condition is true
Combine matched rows
Result Table
Output
We start with two tables, check each pair of rows against the ON condition, keep only matching pairs, then combine their columns into the result.
Execution Sample
SQL
SELECT A.id, A.name, B.salary
FROM Employees A
INNER JOIN Salaries B
ON A.id = B.emp_id;
This query joins Employees and Salaries tables where employee IDs match, returning employee id, name, and salary.
Execution Table
StepEmployees.idEmployees.nameSalaries.emp_idSalaries.salaryON Condition (A.id = B.emp_id)ActionOutput Row
11Alice15000TrueInclude row(1, Alice, 5000)
21Alice26000FalseExclude row
32Bob15000FalseExclude row
42Bob26000TrueInclude row(2, Bob, 6000)
53Charlie37000TrueInclude row(3, Charlie, 7000)
63Charlie48000FalseExclude row
7EndNo more rowsQuery complete
💡 All pairs checked; only rows where Employees.id equals Salaries.emp_id are included.
Variable Tracker
VariableStartAfter Step 1After Step 4After Step 5Final
Current Employees.idNone1233
Current Salaries.emp_idNone1234
Output RowsEmpty[(1, Alice, 5000)][(1, Alice, 5000), (2, Bob, 6000)][(1, Alice, 5000), (2, Bob, 6000), (3, Charlie, 7000)][(1, Alice, 5000), (2, Bob, 6000), (3, Charlie, 7000)]
Key Moments - 2 Insights
Why are some rows from Employees or Salaries not in the output?
Only rows where the ON condition is true (Employees.id = Salaries.emp_id) are included, as shown in execution_table rows 2, 3, and 6 where condition is false and rows are excluded.
Does INNER JOIN include rows without matches in the other table?
No, INNER JOIN only includes rows with matching pairs. The execution_table shows excluded rows when ON condition is false, confirming this.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, what is the output row at step 4?
A(1, Alice, 6000)
B(2, Bob, 5000)
C(2, Bob, 6000)
D(3, Charlie, 7000)
💡 Hint
Check the Output Row column at step 4 in the execution_table.
At which step does the ON condition first become false?
AStep 2
BStep 1
CStep 3
DStep 5
💡 Hint
Look at the ON Condition column in the execution_table to find the first 'False'.
If Salaries.emp_id 4 had a matching Employees.id 4, what would happen to the output?
AAll rows would be excluded
BA new output row with id 4 would be added
CNo change, because INNER JOIN ignores new matches
DOnly Salaries rows would appear
💡 Hint
Refer to variable_tracker showing how output rows grow when ON condition is true.
Concept Snapshot
INNER JOIN combines rows from two tables where the ON condition is true.
Syntax: SELECT columns FROM A INNER JOIN B ON condition;
Only matching rows appear in the result.
Non-matching rows are excluded.
Useful to combine related data from two tables.
Full Transcript
This visual execution shows how INNER JOIN works by checking each pair of rows from two tables against the ON condition. Only pairs where the condition is true are included in the output. The example joins Employees and Salaries tables on employee ID. The execution table traces each step, showing which rows match and are included or excluded. The variable tracker shows how output rows build up. Key moments clarify why some rows are excluded and that INNER JOIN only keeps matching rows. The quiz tests understanding of output rows and condition checks. The snapshot summarizes the INNER JOIN concept and syntax.