Count of Distinct Product Categories
Whetcode Supply is redesigning the shop's navigation. Each top-level menu entry costs a fixed fee to have designed, so before anything is drawn the founder wants a single number: how many different kinds of thing the shop actually sells.
category is a plain label repeated on every product row — there is no separate table of categories to consult. So the number of products is not the number of categories, and the two are easy to confuse when the catalogue is this small. Reading it off the page works on five rows and stops working the week the catalogue reaches five hundred.
products — one row per item in the catalogue. category is the shelf the item sits on.
| id | name | category | price |
|---|---|---|---|
| 1 | Wireless Mouse | electronics | 25.0 |
| 2 | Standing Desk | furniture | 350.0 |
| 3 | Desk Lamp | furniture | 40.0 |
| 4 | Mechanical Keyboard | electronics | 85.0 |
| 5 | Notebook Set | office | 12.0 |
The table already exists in the database — there is nothing to create or load.
Task: Write a query returning one row with a single column, num_categories, holding how many different category values appear across the catalogue.
Example output — shape only. If seven different categories were in use, the single row would read:
| num_categories |
|---|
| 7 |
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in