Bird
0
0

Given the tables employees(id, name) and departments(id, name, manager_id), what will this query return?

medium📝 query result Q13 of 15
SQL - Subqueries
Given the tables employees(id, name) and departments(id, name, manager_id), what will this query return?
SELECT e.name FROM employees e WHERE e.id IN (SELECT d.manager_id FROM departments d);
ASyntax error due to subquery.
BNames of all employees regardless of department.
CNames of employees who are not managers.
DNames of employees who are managers of any department.
Step-by-Step Solution
Solution:
  1. Step 1: Understand the subquery

    The subquery SELECT d.manager_id FROM departments d returns all manager IDs from departments.
  2. Step 2: Analyze the main query

    The main query selects employee names where their ID is in the list of manager IDs, so it returns employees who manage departments.
  3. Final Answer:

    Names of employees who are managers of any department. -> Option D
  4. Quick Check:

    Subquery filters managers = Names of employees who are managers of any department. [OK]
Quick Trick: IN with subquery filters matching IDs [OK]
Common Mistakes:
MISTAKES
  • Thinking it returns all employees
  • Confusing managers with non-managers
  • Assuming syntax error in subquery

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes