List Unique Product CategoriesEasy

List Unique Product Categories

EasySQLPractice library · +10 XPdistinct valuessqlproducts

A retail store wants to understand the variety of products it offers.

Consider the following table:

  • products (product_id integer, category varchar(50), price numeric(10,2))

Return a list of all unique product categories. The results should be ordered alphabetically by category name. NULL categories should be ignored. Empty results are possible if no products exist.

Tables

CREATE TABLE products (
  product_id integer PRIMARY KEY,
  category varchar(50),
  price numeric(10,2)
);

Example data

INSERT INTO products (product_id, category, price)
VALUES
(1, 'Electronics', 199.99),
(2, 'Clothing', 49.50),
(3, 'Electronics', 299.00),
(4, 'Home Goods', 75.20),
(5, 'Clothing', 25.00),
(6, 'Books', 15.99),
(7, 'Electronics', 99.99),
(8, 'Home Goods', 120.00);

Your query is also checked on hidden datasets with different data.

Hints