I have three tables:- items, category & itemscategory
Each item can have several categories associated with it.
Currently I have a query which allows you to select one category, which will output all items associated with that category.
What I’m trying to achieve is to be able to select several categories at once
So far I have come up with
SELECT itemname, COUNT(categoryid) AS Total
FROM items LEFT JOIN itemscategory
ON items.id = itemsid
WHERE categoryid IN ('1', '2', '3', '4')
GROUP BY items.id
HAVING Total = '4'
This query appears to work, but before I attempt to incorporate it into my PHP Code, I would just like some confirmation that it’s the best solution to the problem.
Many Thanks








Bookmarks