Bird
0
0

Consider tables:

medium📝 query result Q5 of 15
SQL - Subqueries
Consider tables:
Orders(order_id, customer_id, amount)
Customers(customer_id, city)
What is the output of this query?
SELECT order_id FROM Orders WHERE customer_id IN (SELECT customer_id FROM Customers WHERE city = 'New York');
AOrder IDs placed by customers not from New York
BOrder IDs placed by customers from New York
CAll order IDs regardless of customer city
DCustomer IDs from New York
Step-by-Step Solution
Solution:
  1. Step 1: Identify subquery output

    The subquery returns customer_id values for customers in New York.
  2. Step 2: Filter orders by customer_id

    The main query selects order_id where customer_id matches any from the subquery.
  3. Final Answer:

    Order IDs placed by customers from New York -> Option B
  4. Quick Check:

    IN filters orders by New York customers [OK]
Quick Trick: IN filters main query by subquery results [OK]
Common Mistakes:
MISTAKES
  • Mixing up order_id and customer_id
  • Assuming it returns all orders
  • Confusing city filter location

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes