MANY MANY filter AND

Hi Everyone!

I’ve found a bunch of articles about a similar problem. Peoples’s articles talk about the MANY_MANY and filter by one parameter.

I want to filter MANY_MANY where parameter = value1 AND parameter = value2 at the same time.

I found a solution:


SELECT shops.*, COUNT(*) AS c

FROM shop_goods, goods, shops

WHERE mm_goods_id = good_id AND mm_shop_id = shop_id

AND goods_name IN ('tea', 'milk', 'wine')

GROUP BY shop_id 

HAVING c = 3

the most important thing is "HAVING c = 3" because i want to find the shops where tea,milk,wine exist at the same time.

How to use this case in yii not to resort to use SQL code?