It depends upon your concept. Can products reside in more than one category at a time? If so, you'll need a link table. Otherwise, you can simply add a column to your products
table, which contains the ID of the category in which it resides.
The former is more complicated since it involves a many-to-many relationship, which is something you should be avoiding as part of your normalization. You'd need to have a link table that looks something like this:
+------------+------------+----------+----------+
| cat_id | prod_id | active | order |
+------------+------------+----------+----------+
| 1 | 1 | 1 | 0 |
| 1 | 2 | 0 | 1 |
| 2 | 2 | 1 | 0 |
+------------+------------+----------+----------+
As you can see, we have four columns (you might only need two):
cat_id
is the ID of the category (from categories
)
prod_id
is the ID of the product (from products
)
active
is a boolean value which indicates whether the product is currently active in this category
order
defines the sort order of this product for the given category
In the sample data above, product ID 1 and 2 both appear in Category 1. However, Product ID 2 is not active. Product ID 2 also appears as the only product in Category 2.