Bird
0
0

What will be the output of this query?

medium📝 query result Q13 of 15
SQL - Subqueries
What will be the output of this query?
SELECT name FROM employees WHERE department_id = (SELECT id FROM departments WHERE name = 'Sales');

Assuming the departments table has one row with name 'Sales' and id 3, and employees table has:
id | name | department_id
1 | Alice | 3
2 | Bob | 2
3 | Carol | 3
ANo rows returned
BBob only
CAlice and Carol
DAlice, Bob, and Carol
Step-by-Step Solution
Solution:
  1. Step 1: Find department id for 'Sales'

    The subquery returns id = 3 for 'Sales' department.
  2. Step 2: Select employees with department_id = 3

    Employees Alice and Carol have department_id 3, so they are selected.
  3. Final Answer:

    Alice and Carol -> Option C
  4. Quick Check:

    Subquery returns 3, employees with department_id 3 selected [OK]
Quick Trick: Match subquery result with main query filter [OK]
Common Mistakes:
MISTAKES
  • Assuming subquery returns multiple rows causing error
  • Selecting employees from wrong department
  • Ignoring subquery result in main query

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes