Bird
0
0

Given tables:

medium📝 query result Q4 of 15
SQL - Subqueries
Given 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 = 'Marketing');
ANames of all employees regardless of department
BNames of employees who work in the Marketing department
CNames of employees who do not work in Marketing
DNames of departments named Marketing
Step-by-Step Solution
Solution:
  1. Step 1: Analyze subquery

    The subquery returns dept_id(s) where dept_name is 'Marketing'.
  2. Step 2: Main query filtering

    The main query selects employee names whose dept_id matches those returned by the subquery.
  3. Final Answer:

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

    IN filters employees by Marketing dept_id(s) [OK]
Quick Trick: IN filters rows matching subquery results [OK]
Common Mistakes:
MISTAKES
  • Assuming it returns all employees
  • Confusing department names with employee names
  • Ignoring the WHERE clause in subquery

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes