サンプルデータがあります:
product(id, parent_id, name)
1 | 0 | Windows
2 | 1 | XP
3 | 1 | 7
manufacturer(id, parent_id, name)
1 | 0 | Westwood Studios
2 | 1 | Red Alert 1
3 | 1 | Red Alert 2
product_manufacturer(product_id, manufacturer_id)
2 | 2
3 | 2
3 | 3
そしてmysql:
SELECT prod.name
FROM `manufacturer` AS child
INNER JOIN `manufacturer` AS parent ON parent.id=child.parent_id
INNER JOIN `product_manufacturer` AS pr_ma ON pr_ma.manufacturer_id=child.manufacturer_id
INNER JOIN `product` AS prod ON pr_ma.product_id=prod.product_id
WHERE parent.id=1
GROUP BY prod.id
parent.id=1 (manufacturer=Westwood Studios)
結果はいつですかXP, 7
parent.id=1
結果がいつであるかを修正する方法はWindows