Bird
0
0

Identify the error in this query:

medium📝 Debug Q14 of 15
PostgreSQL - Subqueries in PostgreSQL
Identify the error in this query:
SELECT * FROM employees WHERE department_id IN SELECT id FROM departments WHERE name = 'HR';
AMissing parentheses around the subquery after IN.
BUsing IN instead of EXISTS.
CSubquery returns multiple columns.
Ddepartment_id cannot be compared with id.
Step-by-Step Solution
Solution:
  1. Step 1: Check syntax for subquery with IN

    The subquery must be enclosed in parentheses after the IN keyword.
  2. Step 2: Identify missing parentheses causing syntax error

    The query lacks parentheses around the subquery, causing invalid syntax.
  3. Final Answer:

    Missing parentheses around the subquery after IN. -> Option A
  4. Quick Check:

    Subquery must be in parentheses after IN [OK]
Quick Trick: Always wrap subqueries in parentheses after IN [OK]
Common Mistakes:
  • Omitting parentheses around subquery
  • Confusing IN with EXISTS syntax
  • Assuming subquery returns multiple columns

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes