Bird
0
0

Given the table orders with column customer_id, what will this query return?

medium📝 query result Q13 of 15
SQL - Advanced Query Patterns
Given the table orders with column customer_id, what will this query return?
SELECT customer_id FROM orders GROUP BY customer_id HAVING COUNT(*) > 2;
AAll customer IDs with exactly 2 orders
BAll customer IDs regardless of order count
CAll customer IDs with less than 2 orders
DAll customer IDs with more than 2 orders
Step-by-Step Solution
Solution:
  1. Step 1: Understand HAVING COUNT(*) > 2 condition

    This filters groups where the count of rows is greater than 2.
  2. Step 2: Apply to customer_id groups

    Only customer IDs with more than 2 orders appear in the result.
  3. Final Answer:

    All customer IDs with more than 2 orders -> Option D
  4. Quick Check:

    HAVING COUNT(*) > 2 means count > 2 [OK]
Quick Trick: HAVING COUNT(*) > N finds groups with more than N rows [OK]
Common Mistakes:
  • Thinking it finds exactly 2 instead of more than 2
  • Confusing WHERE and HAVING clauses
  • Ignoring GROUP BY effect

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes