Bird
0
0

Consider the query:

medium📝 query result Q5 of 15
SQL - Subqueries
Consider the query:
SELECT emp_name FROM employees WHERE dept_id IN (SELECT dept_id FROM departments WHERE location = 'NY');

What does this query return?
AEmployees working outside NY
BEmployees working in departments located in NY
CAll employees regardless of location
DError because subquery returns multiple rows
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the subquery

    The subquery returns all dept_id values where location is 'NY'.
  2. Step 2: Understand the main query filter

    The main query selects employee names whose dept_id is in the list returned by the subquery.
  3. Final Answer:

    Employees working in departments located in NY -> Option B
  4. Quick Check:

    IN with subquery filters employees by department location [OK]
Quick Trick: IN allows subquery to return multiple values for filtering [OK]
Common Mistakes:
MISTAKES
  • Thinking subquery with multiple rows causes error with IN
  • Confusing location filter with employee location
  • Assuming all employees are returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes