我有两张桌子,产品和类别。一个产品可以分为多个类别。
product (<product_id>, name, desc, price)
category (<category_id>, slug, display_name)
product_category(<category_id>, <product_id>)
name | desc | categories
------------------------------------------------------------------
The One Ring One ring to rule them all Magical Item, Jewelry
其中魔法物品是一个类别,而珠宝是另一个类别(不是现实生活中的例子)。索伦不是要我开店)。
SELECT name, desc, categories.display_name FROM product, category,
category_product WHERE product.product_id = category_product.product_id AND
category_product.category_id = category.category_id