Bird
0
0

Given tables Employees and Departments, what will this query return?

medium📝 query result Q4 of 15
SQL - LEFT and RIGHT JOIN
Given tables Employees and Departments, what will this query return?
SELECT Employees.name, Departments.name FROM Employees LEFT JOIN Departments ON Employees.dept_id = Departments.id;
AOnly departments that have employees.
BAll employees with their department names; NULL if no department assigned.
CAll departments with their employees; NULL if no employee assigned.
DOnly employees who have a matching department.
Step-by-Step Solution
Solution:
  1. Step 1: Understand LEFT JOIN effect on Employees and Departments

    LEFT JOIN keeps all rows from Employees (left table) and matches Departments (right table). If no match, department columns are NULL.
  2. Step 2: Analyze query output

    Query returns all employees with their department names or NULL if no department assigned.
  3. Final Answer:

    All employees with their department names; NULL if no department assigned. -> Option B
  4. Quick Check:

    LEFT JOIN output = D [OK]
Quick Trick: LEFT JOIN keeps all left rows, unmatched right columns are NULL [OK]
Common Mistakes:
MISTAKES
  • Thinking only matching rows are returned
  • Confusing left and right tables
  • Assuming NULLs appear in left table columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes