EasySQL
List Unique Product Categories
SQLDatabases
Write a SQL query that returns the distinct categories found in theproducts table, sorted alphabetically.
Table: `products`
| id | name | price | category |
|---|---|---|---|
| 1 | Laptop | 999 | Electronics |
| 2 | Wireless Mouse | 29 | Electronics |
| 3 | Standing Desk | 349 | Furniture |
| 4 | Office Chair | 199 | Furniture |
| 5 | Notebook | 5 | Stationery |
| 6 | Pen Set | 8 | Stationery |
| 7 | Headphones | 79 | Electronics |
Expected output (column: category)
Electronics
Furniture
StationeryUse
SELECT DISTINCTto eliminate duplicate category values.
Sample tests
Test #17 products across 3 distinct categories
Input: "CREATE TABLE products (id INTEGER, name TEXT, price INTEGER, category TEXT);\nINSERT INTO products VALUES\n (1, 'Laptop', 999, 'Electronics'),\n (2, 'Wireless Mouse', 29, 'Electronics'),\n (3, 'Standing Desk', 349, 'Furniture'),\n (4, 'Office Chair', 199, 'Furniture'),\n (5, 'Notebook', 5, 'Stationery'),\n (6, 'Pen Set', 8, 'Stationery'),\n (7, 'Headphones', 79, 'Electronics');"
Output: "Electronics\nFurniture\nStationery"