Bird
0
0

Given the table employees with columns id, name, and manager_id, what will this query return?

medium📝 query result Q13 of 15
SQL - INNER JOIN
Given the table employees with columns id, name, and manager_id, what will this query return?
SELECT e1.name AS Employee, e2.name AS Manager FROM employees e1 LEFT JOIN employees e2 ON e1.manager_id = e2.id;
ASyntax error due to missing WHERE clause
BList of employees with their managers' names, NULL if no manager
CList of employees without managers only
DList of managers with their employees' names
Step-by-Step Solution
Solution:
  1. Step 1: Understand the LEFT JOIN on self join

    The query joins the employees table to itself using aliases e1 and e2, matching e1.manager_id to e2.id to find each employee's manager.
  2. Step 2: Interpret the SELECT columns and join type

    Using LEFT JOIN means all employees (e1) appear, even if they have no manager (e2.name will be NULL). The SELECT shows employee and manager names.
  3. Final Answer:

    List of employees with their managers' names, NULL if no manager -> Option B
  4. Quick Check:

    LEFT JOIN self join shows all employees with managers [OK]
Quick Trick: LEFT JOIN keeps all employees, shows NULL for missing managers [OK]
Common Mistakes:
MISTAKES
  • Confusing employee and manager columns
  • Thinking it lists only managers or only employees without managers
  • Assuming syntax error without WHERE clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes