I think that you are after this:
SELECT image_id
FROM list
WHERE (style_id, style_value) IN ((24,'red'),(25,'big'),(27,'round'))
GROUP BY image_id
HAVING count(distinct style_id, style_value)=3
You can't use AND, because values can't be 24 red
and 25 big
and 27 round
at the same time in the same row, but you need to check the presence of style_id, style_value
in multiple rows, under the same image_id
.
In this query I'm using IN (that, in this particular example, is equivalent to an OR), and I am counting the distinct rows that match. If 3 distinct rows match, it means that all 3 attributes are present for that image_id
, and my query will return it.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…