brand(id, parent_id, name)
1 | 0 | Apple
2 | 0 | Samsung
3 | 1 | Iphone 3S
4 | 1 | Iphone 4S
product(id, name)
1 | OS
2 | Andriod
product_brand(product_id, brand_id)
1 | 3
1 | 4
和 mysql:如何获取product name
何时brand name = Apple
SELECT * FROM product_brand
LEFT JOIN brand ON brand.id = product_brand.brand_id
WHERE brand.id = 1 // Apple
例如:如果得到 Apple(id=1) 是结果 => 操作系统,如果得到三星(id=2) 是结果 => Andriod