Bird
0
0

What will be the output of this query?

medium📝 query result Q4 of 15
PostgreSQL - Subqueries in PostgreSQL
What will be the output of this query?
SELECT name FROM employees WHERE department_id IN (SELECT id FROM departments WHERE location = 'NY');
ANames of employees working outside NY
BNames of all employees regardless of location
CNames of employees working in departments located in NY
DSyntax error due to missing JOIN
Step-by-Step Solution
Solution:
  1. Step 1: Understand the subquery

    The subquery selects department IDs where location is 'NY'.
  2. Step 2: Main query filters employees by those department IDs

    Only employees in those departments are selected.
  3. Final Answer:

    Names of employees working in departments located in NY -> Option C
  4. Quick Check:

    Subquery filters departments, main query filters employees [OK]
Quick Trick: Subqueries can filter main query results by related data [OK]
Common Mistakes:
  • Assuming all employees are returned
  • Thinking subquery causes syntax error without JOIN
  • Confusing IN with equality operator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes