Bird
0
0

What will this query return?

medium📝 query result Q5 of 15
PostgreSQL - Subqueries in PostgreSQL
What will this query return?
SELECT id FROM customers WHERE EXISTS (SELECT 1 FROM orders WHERE orders.customer_id = customers.id AND orders.amount > 100);
ACustomer IDs with orders over 100 amount
BCustomer IDs with no orders
CAll customer IDs
DAn error due to missing GROUP BY
Step-by-Step Solution
Solution:
  1. Step 1: Analyze the subquery condition

    The subquery looks for orders with amount greater than 100 for each customer.
  2. Step 2: Understand EXISTS effect

    EXISTS returns true if such orders exist, so customers with orders over 100 are selected.
  3. Final Answer:

    Customer IDs with orders over 100 amount -> Option A
  4. Quick Check:

    EXISTS filters customers with large orders = C [OK]
Quick Trick: EXISTS filters rows based on subquery conditions [OK]
Common Mistakes:
  • Assuming it returns customers without orders
  • Expecting all customers regardless of orders
  • Thinking GROUP BY is required here

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes