Bird
0
0

Given tables:

medium📝 query result Q4 of 15
SQL - LEFT and RIGHT JOIN
Given tables:
Employees(id, name)
Departments(id, dept_name, manager_id)
Query:
SELECT e.name, d.dept_name FROM Employees e LEFT JOIN Departments d ON e.id = d.manager_id;
What will be the output if an employee is not a manager of any department?
AEmployee name with empty string for dept_name
BEmployee name excluded from result
CEmployee name with NULL for dept_name
DError due to missing department
Step-by-Step Solution
Solution:
  1. Step 1: Understand LEFT JOIN effect on unmatched rows

    Employees not matching any department manager will still appear.
  2. Step 2: Check values for unmatched right table columns

    Columns from Departments will be NULL if no match.
  3. Final Answer:

    Employee name with NULL for dept_name -> Option C
  4. Quick Check:

    LEFT JOIN unmatched right columns = NULL [OK]
Quick Trick: LEFT JOIN unmatched right columns show as NULL [OK]
Common Mistakes:
MISTAKES
  • Expecting empty string instead of NULL
  • Thinking unmatched rows are excluded
  • Assuming query errors on no match

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes