All products of each category in one line
Medium
Show each category and products: its product names joined with ', ', in alphabetical order of name.
Tables: customers(customer_id, name, city, country, joined) · products(product_id, name, category, price) · orders(order_id, customer_id, order_date, status) · order_items(order_id, product_id, quantity, unit_price)
Your query✔ Solved
Show the expected result
| category | products |
|---|---|
| Books | Deep Learning (book), Python Crash Course (book), SQL Pocket Guide |
| Electronics | 27-inch monitor, Mechanical keyboard, Noise-cancelling headphones, USB-C hub, Wireless mouse |
| Furniture | Desk lamp, Ergonomic chair, Standing desk |
| Grocery | Coffee beans 1 kg, Green tea, 100 bags |
| Stationery | A5 notebook, Gel pens, pack of 10 |
5 rows
Show a solution
SELECT category, GROUP_CONCAT(name, ', ') AS products FROM (SELECT category, name FROM products ORDER BY name) GROUP BY category;
SQL used
New to SQL? The free SQL course teaches everything these problems use, with a self-checking exercise in every lesson.