Bird
0
0

Identify the error in the following SQL query: SELECT COUNT(*) FROM orders WHERE COUNT(order_id) > 5;

medium📝 Debug Q6 of 15
SQL - Aggregate Functions
Identify the error in the following SQL query: SELECT COUNT(*) FROM orders WHERE COUNT(order_id) > 5;
AMissing GROUP BY clause
BCOUNT(*) should be COUNT(order_id)
CCOUNT cannot be used in WHERE clause
DCOUNT(order_id) should be COUNT(*)
Step-by-Step Solution
Solution:
  1. Step 1: Understand aggregate functions usage

    Aggregate functions like COUNT cannot be used directly in WHERE clause.
  2. Step 2: Correct usage of COUNT in filtering

    Use HAVING clause to filter on aggregate results, not WHERE.
  3. Final Answer:

    COUNT cannot be used in WHERE clause -> Option C
  4. Quick Check:

    Aggregate functions not allowed in WHERE [OK]
Quick Trick: Use HAVING, not WHERE, for aggregate filters [OK]
Common Mistakes:
MISTAKES
  • Using COUNT in WHERE clause
  • Confusing WHERE and HAVING
  • Assuming COUNT can filter rows directly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes