Bird
0
0

Given tables:

medium📝 query result Q4 of 15
SQL - LEFT and RIGHT JOIN
Given tables:
Employees:
ID | Name | DeptID
1 | Alice | 10
2 | Bob | 20
3 | Carol | NULL

Departments:
DeptID | DeptName
10 | Sales
30 | Marketing

What will be the result of:
SELECT Employees.Name, Departments.DeptName FROM Employees RIGHT JOIN Departments ON Employees.DeptID = Departments.DeptID;?
AAlice | Sales<br>Bob | NULL<br>NULL | Marketing
BAlice | Sales<br>NULL | Marketing
CAlice | Sales<br>Bob | Sales<br>NULL | Marketing
DAlice | Sales<br>Carol | NULL<br>NULL | Marketing
Step-by-Step Solution
Solution:
  1. Step 1: Identify right table rows

    Departments has DeptID 10 and 30, so both rows appear.
  2. Step 2: Match Employees to Departments

    Only Alice has DeptID 10 matching Sales; no employee matches Marketing (30).
  3. Final Answer:

    Alice | Sales
    NULL | Marketing
    -> Option B
  4. Quick Check:

    RIGHT JOIN keeps all right rows, unmatched left columns NULL = Alice | Sales
    NULL | Marketing [OK]
Quick Trick: RIGHT JOIN shows all right rows, unmatched left columns as NULL [OK]
Common Mistakes:
MISTAKES
  • Including employees with NULL DeptID
  • Assuming unmatched left rows appear
  • Mixing up which table is right

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes