I have the following table structure:
id product_id attribute_id attribute_val_id
138 18 29 304
137 17 29 304
78 17 20 161
79 17 21 301
80 17 22 94
I want to select product Id (for example 17) which has attribute_val_id equal to: 304 and 161 and 301.
I’ve tried:
SELECT DISTINCT product_id FROM `products_attribute_rel`
WHERE attribute_val_id = 304
AND attribute_val_id = 161
AND attribute_val_id = 301
But with this I get empty results. MYSQL IN sentence also makes no good.
Any ideas ?
You should have (attribute_val_id, product_id) index on the table to make the query faster.