Bird
0
0

Given tables employees and departments with columns employees.dept_id and departments.id, what will this query return?

medium📝 query result Q4 of 15
SQL - Advanced Joins
Given tables employees and departments with columns employees.dept_id and departments.id, what will this query return?
SELECT e.name, d.name FROM employees e LEFT JOIN departments d ON e.dept_id = d.id WHERE d.name IS NULL;
AAll employees and all departments
BEmployees who belong to a department
CEmployees without a matching department
DDepartments without employees
Step-by-Step Solution
Solution:
  1. Step 1: Understand LEFT JOIN with WHERE condition

    LEFT JOIN keeps all employees; WHERE d.name IS NULL filters those without matching department.
  2. Step 2: Interpret the result

    Only employees whose dept_id does not match any department id will appear.
  3. Final Answer:

    Employees without a matching department -> Option C
  4. Quick Check:

    LEFT JOIN + WHERE NULL on right = unmatched left rows [OK]
Quick Trick: WHERE NULL on joined table filters unmatched rows [OK]
Common Mistakes:
MISTAKES
  • Assuming WHERE filters before join
  • Thinking it returns matched employees
  • Confusing departments without employees

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes