Eav query e tavoli
-
12-11-2019 - |
Domanda
Ora ho 4 tavoli:
table categories:
-id
-category
table products:
-id
-product
-price
-image
table attributes:
-id
-attribute
-product_id
table values:
-product_id
-attribute_id
-value
E sto interrogando con:
SELECT `id`, `product`, `price`, `image` FROM `products` WHERE `category_id` = $category->id
Ora ho ottenuto una serie di prodotti per questa categoria e ho bisogno di ottenere le sue proprietà: Next query:
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)
E ottiene gli attributi con valori ma mi chiedo una cosa: se è possibile sbarazzarsi 'product_id'
colonna in table attributes
E ottenere attributi e valori senza quella colonna? Ora è un sacco di attributi duplicanti, ad esempio:
table attributes
-id 1
-attribute Weight
-product_id 1
-id 2
-attribute Weight
-product_id 2
Mentre voglio solo:
-id 1
-attribute Weight
Ci scusiamo per il mio inglese, se una parte del mio post ha bisogno di più spiegazioni per favore lasciami ora
Nessuna soluzione corretta
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow