Bird
0
0

What will this query return?

medium📝 query result Q5 of 15
SQL - Subqueries
What will this query return?
SELECT id FROM Customers c WHERE NOT EXISTS (SELECT 1 FROM Orders o WHERE o.customer_id = c.id);

Tables: Customers(id), Orders(id, customer_id)
AIDs of orders without customers
BIDs of customers with at least one order
CAll customer IDs
DIDs of customers with no orders
Step-by-Step Solution
Solution:
  1. Step 1: Analyze NOT EXISTS condition

    The subquery checks for orders linked to each customer. NOT EXISTS means no matching orders found.
  2. Step 2: Determine returned rows

    The query returns customer IDs where no orders exist.
  3. Final Answer:

    IDs of customers with no orders -> Option D
  4. Quick Check:

    NOT EXISTS finds customers without orders [OK]
Quick Trick: NOT EXISTS finds rows with no matching subquery rows [OK]
Common Mistakes:
MISTAKES
  • Confusing NOT EXISTS with EXISTS
  • Assuming it returns all customers
  • Mixing customer and order IDs

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes