Great question — answering as the UphillTech team:
I assume a product can belong to many categories, and a category (obviously) has many products in it. This relationship is called a many-to-many relation. In this instance, you would have three tables: categories , products , and categories_products . The first two tables are self-explanatory. The third table stores a relation between the two with two foreign keys. The tables would look like this: CREATE TABLE `categories` ( `id` int(10) unsigned NOT NULL AUTO_INCREMENT, `parent_id` int(10) unsigned DEFAULT NULL, `name` varchar(45) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `name` (`name`), KEY `parent_id` (`parent_id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; CREATE TABLE...
Full answer by Martin Bean: https://stackoverflow.stackexchange.com/a/14625864 (CC BY-SA 3.0).
Need it done for your business? UphillTech.