今私は4つのテーブルを持っています:
table categories:
-id
-category
table products:
-id
-product
-price
-image
table attributes:
-id
-attribute
-product_id
table values:
-product_id
-attribute_id
-value
そして、私は次のようにクエリしています:
SELECT `id`, `product`, `price`, `image` FROM `products` WHERE `category_id` = $category->id
これで、このカテゴリの製品の配列を取得し、そのプロパティを取得する必要があります。次のクエリ:
SELECT `products`.`id` AS `product_id`,
`attributes`.`attribute`,
`values`.`value`
FROM `products` LEFT JOIN `attributes` ON (`attributes`.`product_id` = `products`.`id`)
LEFT JOIN `values` ON (`values`.`product_id` = `products`.`id`
AND `values`.`attribute_id` = `attributes`.`id`)
WHERE `products`.`id` IN ($ids)
そして、それは値を持つ属性を取得しますが、私は1つのことについて疑問に思っています:'product_id'
列を取り除き、table attributes
その列なしで属性と値を取得することが可能かどうか?これで、たとえば次のように、属性を複製することができます。
table attributes
-id 1
-attribute Weight
-product_id 1
-id 2
-attribute Weight
-product_id 2
私が欲しい間:
-id 1
-attribute Weight
私の英語で申し訳ありませんが、私の投稿の一部にさらに説明が必要な場合は、今すぐ教えてください