Bird
0
0

Which SQL statement correctly groups rows by the category column in the products table?

easy📝 Syntax Q3 of 15
SQL - GROUP BY and HAVING
Which SQL statement correctly groups rows by the category column in the products table?
ASELECT category, COUNT(*) FROM products ORDER BY category;
BSELECT category, COUNT(*) FROM products GROUP BY category;
CSELECT category, COUNT(*) FROM products WHERE category GROUP BY category;
DSELECT category, COUNT(*) FROM products HAVING category;
Step-by-Step Solution
Solution:
  1. Step 1: Identify GROUP BY syntax

    The correct syntax to group rows is to use GROUP BY column_name after the FROM clause.
  2. Step 2: Analyze options

    SELECT category, COUNT(*) FROM products GROUP BY category; uses GROUP BY category correctly. Options B, C, and D misuse ORDER BY, WHERE, or HAVING clauses.
  3. Final Answer:

    SELECT category, COUNT(*) FROM products GROUP BY category; -> Option B
  4. Quick Check:

    GROUP BY follows FROM and precedes HAVING/ORDER BY [OK]
Quick Trick: GROUP BY follows FROM, not WHERE or HAVING [OK]
Common Mistakes:
MISTAKES
  • Using WHERE instead of GROUP BY
  • Confusing ORDER BY with GROUP BY
  • Misusing HAVING without GROUP BY

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes