Build a Product–Tag Junction Table
MediumDescription
products.tags stores a list such as {audio,wireless} in one column. Move it into a
junction table:
- Create
product_tagswithproduct_id(a whole number that must be a real product) andtag(text), where the pairproduct_id,tagis the primary key. - Fill it with one row for every tag of every product, in a single
INSERT. - Show
tagandproduct_idof the rows taggedbestsellerorfiction.
End your query with ORDER BY tag, product_id.
Tables
| products |
|---|
| product_id (PK) |
| product_name |
| tags |