Bird
0
0

Given tables:

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

    The subquery finds the dept_id for the department named 'HR'.
  2. Step 2: Apply the subquery result in the outer query

    The outer query selects employee names whose dept_id matches the HR dept_id.
  3. Final Answer:

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

    Subquery filters employees by HR dept_id = Names of employees who work in the HR department [OK]
Quick Trick: Subquery filters outer query rows by matching values [OK]
Common Mistakes:
MISTAKES
  • Assuming subquery returns multiple rows error
  • Selecting all employees ignoring filter
  • Confusing employees not in HR

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes