mysql - Show Products That Are In Multiple Categories
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
精彩评论