Bird
0
0

Given these tables:

medium📝 query result Q13 of 15
SQL - LEFT and RIGHT JOIN
Given these tables:

Employees
id | name
1 | Alice
2 | Bob
3 | Carol

Sales
emp_id | amount
1 | 100
3 | 200

What is the result of:
SELECT Employees.name, Sales.amount FROM Employees LEFT JOIN Sales ON Employees.id = Sales.emp_id;
A[('Alice', 100), ('Bob', 0), ('Carol', 200)]
B[('Alice', 100), ('Bob', NULL), ('Carol', 200)]
C[('Alice', 100), ('Carol', 200)]
D[('Bob', NULL)]
Step-by-Step Solution
Solution:
  1. Step 1: Match Employees with Sales using LEFT JOIN

    All Employees rows appear. For matching emp_id in Sales, amount is shown; else NULL.
  2. Step 2: Map each employee to sales amount or NULL

    Alice (id=1) matches 100, Bob (id=2) no match so NULL, Carol (id=3) matches 200.
  3. Final Answer:

    [('Alice', 100), ('Bob', NULL), ('Carol', 200)] -> Option B
  4. Quick Check:

    LEFT JOIN keeps all left rows with NULL for no match [OK]
Quick Trick: LEFT JOIN shows NULL for unmatched right rows, not zero [OK]
Common Mistakes:
MISTAKES
  • Replacing NULL with zero
  • Omitting unmatched rows
  • Confusing LEFT JOIN with INNER JOIN

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes