Question

Maintenant, j'ai 4 tables:

table categories:
-id
-category

table products:
-id
-product
-price
-image

table attributes:
-id
-attribute
-product_id

table values:
-product_id
-attribute_id
-value

Et je me demande:

SELECT `id`, `product`, `price`, `image` FROM `products` WHERE `category_id` = $category->id

Maintenant, j'ai eu une gamme de produits pour cette catégorie et j'ai besoin d'obtenir ses propriétés: prochaine requête:

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)

Et c'est obtenir les attributs avec des valeurs mais je me pose des questions sur une chose: s'il est possible de se débarrasser de 'product_id' colonne table attributes et obtenir des attributs et des valeurs sans cette colonne? Maintenant, c'est tout un tas d'attributs de duplication par exemple:

table attributes 
-id 1
-attribute Weight
-product_id 1

-id 2
-attribute Weight
-product_id 2

Pendant que je veux juste:

-id 1
-attribute Weight

Désolé pour mon anglais, si une partie de mon message a besoin de plus d'explication, laissez-moi maintenant

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top