Bird
0
0

What will be the output of this query?

medium📝 query result Q5 of 15
PostgreSQL - Aggregate Functions and GROUP BY
What will be the output of this query?
SELECT COUNT(DISTINCT category) FROM products;
ATotal number of rows in products
BNumber of unique categories in products
CSum of all category values
DError because DISTINCT cannot be used inside COUNT
Step-by-Step Solution
Solution:
  1. Step 1: Understand COUNT(DISTINCT)

    COUNT(DISTINCT column) counts unique values in that column.
  2. Step 2: Apply to category column

    The query returns how many different categories exist in the products table.
  3. Final Answer:

    Number of unique categories in products -> Option B
  4. Quick Check:

    COUNT(DISTINCT) = count unique values [OK]
Quick Trick: COUNT(DISTINCT) counts unique entries [OK]
Common Mistakes:
  • Thinking it counts all rows
  • Assuming syntax error with DISTINCT
  • Confusing with SUM()

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes