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 id FROM customers WHERE EXISTS SELECT * FROM orders WHERE orders.customer_id = customers.id;
AIncorrect table alias usage
BUsing SELECT * instead of SELECT 1 in EXISTS
CMissing WHERE clause in subquery
DMissing parentheses around the subquery after EXISTS
Step-by-Step Solution
Solution:
  1. Step 1: Check EXISTS syntax

    The EXISTS keyword must be followed by a subquery enclosed in parentheses.
  2. Step 2: Identify the error in the query

    The query misses parentheses around the subquery, causing a syntax error.
  3. Final Answer:

    Missing parentheses around the subquery after EXISTS -> Option D
  4. Quick Check:

    EXISTS requires parentheses around subquery [OK]
Quick Trick: Always put parentheses after EXISTS [OK]
Common Mistakes:
  • Omitting parentheses after EXISTS
  • Thinking SELECT * is invalid in EXISTS
  • Confusing alias usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes