There are two tables: Good(name, id) and GoodHasAttribute(good_id, attribute_id, value) . The GoodHasAttribute table stores attribute values for each item. I need to extract products with the specified properties. There is currently the following query:
SELECT * FROM Good t JOIN GoodHasAttribute goodAttributes ON (`goodAttributes`.`good_id`=`t`.`id`) and ( ((goodAttributes.attribute_id=1) AND (goodAttributes.value LIKE '%белый%')) or ((goodAttributes.attribute_id=3) AND (goodAttributes.value LIKE '%красный%')) ) It returns to me only those products in which there is at least one attribute, but I need with both.
So far, I have thought up to remove the grouping of conditions and or replace with and , but in this case I will also receive goods with attributes " attribute_id=1, value=красный " and " attribute_id=3, value=белый ".
Which query will retrieve the data I need?