-1
私はお互いに関連商品を2つ持っています。ネストされた関連製品を取得するmysql
product
---------------------------------------------
product_id | Name | creation_date
---------------------------------------------
1 A 2017-03-11 11:30:13
2 B 2017-03-12 12:30:12
3 C 2017-03-13 13:30:45
4 D 2017-03-14 14:30:45
5 E 2017-03-15 15:30:45
product_related
---------------------------------------------
related_id | product_id | related_product_id
---------------------------------------------
1 1 2
2 2 5
3 3 1
4 4 3
私はすべての関連製品を間接的または直接的に取得する必要があります。
If @ProductID = 1, then I need Product ID's 2,3,4,5
If @ProductID = 2, then I need Product ID's 1,3,4,5
If @ProductID = 3, then I need Product ID's 1,2,4,5
If @ProductID = 4, then I need Product ID's 1,2,3,5
If @ProductID = 5, then I need Product ID's 1,2,3,4
実行パフォーマンスを向上させるには、product_relatedテーブルのデザインを変更する必要がある場合は問題ありません。
を、そうではありませんか? – Strawberry
@strawberry、はい要件は複雑ですが、これは私が必要とするものです –
私の関連する構造に必要な変更があれば気にしません –