Bird
0
0

Identify the error in this query:

medium📝 Debug Q14 of 15
SQL - GROUP BY and HAVING

Identify the error in this query:

SELECT category, COUNT(*) FROM products HAVING COUNT(*) > 10 GROUP BY category;
AMissing WHERE clause before HAVING
BHAVING clause used before GROUP BY
CCOUNT(*) cannot be used in HAVING
DGROUP BY should be replaced with ORDER BY
Step-by-Step Solution
Solution:
  1. Step 1: Check order of clauses in SQL

    The correct order is GROUP BY first, then HAVING.
  2. Step 2: Identify incorrect clause order

    The query places HAVING before GROUP BY, causing syntax error.
  3. Final Answer:

    HAVING clause used before GROUP BY -> Option B
  4. Quick Check:

    GROUP BY before HAVING [OK]
Quick Trick: GROUP BY must come before HAVING [OK]
Common Mistakes:
MISTAKES
  • Placing HAVING before GROUP BY
  • Thinking HAVING needs WHERE before it
  • Replacing GROUP BY with ORDER BY incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes