0
0
SQLquery~10 mins

INNER JOIN with multiple conditions in SQL - Step-by-Step Execution

Choose your learning style9 modes available
Concept Flow - INNER JOIN with multiple conditions
Start with Table A
Start with Table B
Check Condition 1: A.col1 = B.col1
Yes
Check Condition 2: A.col2 = B.col2
Yes
Combine rows from A and B
Add combined row to result
Repeat for all rows in A and B
End with result set of matched rows
The INNER JOIN compares rows from two tables and includes only those where all specified conditions are true.
Execution Sample
SQL
SELECT *
FROM Employees E
INNER JOIN Departments D
ON E.DeptID = D.DeptID
AND E.Location = D.Location;
This query joins Employees and Departments where both DeptID and Location match.
Execution Table
StepE.DeptIDE.LocationD.DeptIDD.LocationCondition 1 (E.DeptID = D.DeptID)Condition 2 (E.Location = D.Location)Row Included?
110NY10NYTrueTrueYes
210NY10LATrueFalseNo
320LA20LATrueTrueYes
420LA30LAFalseTrueNo
530NY30NYTrueTrueYes
630NY10NYFalseTrueNo
7------End of rows
💡 All rows compared; only rows where both conditions are true are included.
Variable Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5After Step 6Final
Row Included?N/AYesNoYesNoYesNoFinal result includes rows 1, 3, and 5
Key Moments - 2 Insights
Why are some rows with matching DeptID excluded?
Rows are excluded if the second condition (Location match) is false, as shown in execution_table rows 2 and 6.
Does INNER JOIN include rows if only one condition matches?
No, both conditions must be true for a row to be included, as seen in rows 2 and 4 where one condition fails.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, at step 4, why is the row not included?
ABecause Condition 2 is false
BBecause both conditions are true
CBecause Condition 1 is false
DBecause both conditions are false
💡 Hint
Check the values under Condition 1 and Condition 2 columns at step 4 in the execution_table.
At which steps are rows included in the result?
ASteps 1, 3, 5
BSteps 2, 4, 6
CSteps 1, 2, 3
DSteps 4, 5, 6
💡 Hint
Look at the 'Row Included?' column in the execution_table for 'Yes' values.
If the second condition (Location match) was removed, what would happen to the included rows?
ANo change in included rows
BMore rows would be included
CFewer rows would be included
DQuery would return no rows
💡 Hint
Removing a condition relaxes the join criteria, so check how many rows satisfy only the first condition.
Concept Snapshot
INNER JOIN with multiple conditions syntax:
SELECT * FROM A INNER JOIN B ON A.col1 = B.col1 AND A.col2 = B.col2;
Only rows matching all conditions appear in the result.
Conditions are combined with AND.
Useful to filter joined rows precisely.
Full Transcript
This visual execution shows how an INNER JOIN with multiple conditions works. We start with two tables, Employees and Departments. For each pair of rows, we check if the DeptID matches and if the Location matches. Only when both conditions are true do we include the combined row in the result. The execution table lists each comparison step, showing which rows pass both conditions and are included. The variable tracker highlights how the inclusion decision changes step by step. Key moments clarify why some rows are excluded despite partial matches. The quiz tests understanding by asking about specific steps and the effect of conditions. This helps beginners see how multiple conditions in INNER JOIN filter the results carefully.