Bird
0
0

What will be the output of this query?

medium📝 query result Q5 of 15
SQL - Subqueries
What will be the output of this query?
SELECT emp_id FROM Employees WHERE dept_id IN (SELECT dept_id FROM Departments WHERE name LIKE '%Sales%');
ANo results because LIKE cannot be used in subqueries
BEmployee IDs working in any department with 'Sales' in its name
CAll employee IDs regardless of department
DEmployee IDs working only in the 'Sales' department
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the subquery condition

    The subquery selects dept_id for departments with names containing 'Sales'.
  2. Step 2: Understand the outer query filter

    The outer query selects emp_id where dept_id matches any from the subquery list.
  3. Final Answer:

    Employee IDs working in any department with 'Sales' in its name -> Option B
  4. Quick Check:

    IN with LIKE filters employees by matching departments [OK]
Quick Trick: IN works with subqueries returning multiple rows [OK]
Common Mistakes:
MISTAKES
  • Thinking LIKE is invalid in subqueries
  • Assuming only exact 'Sales' matches
  • Ignoring IN allows multiple matches

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes