开发者

mysql - Show Products That Are In Multiple Categories

开发者 https://www.devze.com 2023-03-31 08:45 出处:网络
I cannot find an answer to this issue. I want to be able to return a query of Virtuemart (Joomla! + Virtuemart) products that are in more than one category. There are currently 8 categories they coul

I cannot find an answer to this issue.

I want to be able to return a query of Virtuemart (Joomla! + Virtuemart) products that are in more than one category. There are currently 8 categories they could be in (which may grow.)

So a user cou开发者_如何学编程ld potentially select any number of categories and I want back a list of only products that are in ALL selected categories.

How could I do a query that handles this in MySQL?


I don't know your tables structure but this example might give you an idea.

select product
from categories
where category in ('cat1','cat2','cat3')
group by product
having count(distinct(category)) = 3
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号