MYSQL: product - attribute relations -




i'm trying figure out relations between products , product attributes. have product table , product_attributes table. product can have multiple attributes. need query finding products have 1 specific attribute , 1 of ones. e.g. product attribute_value_id "1" , product must have attribute_value_id in (2, 3, 4)

i thought it, not:

select distinct p.product_id  `product` p  join `product_attribute` pa on (p.product_id = pa.product_id)  pa.attribute_value_id = 1 , pa.attribute_value_id in(2, 3, 4)  

product

product_id

product_attribute

product_id | attribute_id | attribute_value_id

attribute_id attribute group (e.g. color, gender) attribute_value_id specific value (e.g. blue, men, women)

in words need prodcuts men blue or red.

any suggestions? thank in advance. appreciated.





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -

python - Read npy file directly from S3 StreamingBody -