Bird
0
0

Given the tables:

medium📝 query result Q13 of 15
SQL - Subqueries
Given the tables:
Employees(emp_id, name, dept_id)
Departments(dept_id, dept_name)
What will this query return?
SELECT name FROM Employees WHERE dept_id IN (SELECT dept_id FROM Departments WHERE dept_name = 'Sales');
ANames of employees who do not work in the Sales department.
BNames of employees who work in the Sales department.
CAll employee names regardless of department.
DAn error because subquery returns multiple rows.
Step-by-Step Solution
Solution:
  1. Step 1: Understand subquery filtering

    The subquery selects dept_id values where dept_name is 'Sales'.
  2. Step 2: Main query filters employees

    The main query selects employee names whose dept_id matches any dept_id from the subquery.
  3. Final Answer:

    Names of employees who work in the Sales department. -> Option B
  4. Quick Check:

    IN filters employees by Sales dept_id [OK]
Quick Trick: IN filters rows matching subquery values [OK]
Common Mistakes:
MISTAKES
  • Thinking it returns employees outside Sales
  • Assuming subquery causes error with multiple rows
  • Ignoring subquery filtering condition

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes