I have a query listing product categories, by supercategory > category. The query counts the number of products in each category (COUNT(ptc.catid))
.
Howewer: the query doesn't let a category appear twice (a category can be linked to multiple supercategories). How can this be re-written so categories (c.title) can be listed under multiple supercategories?
SELECT
s.supercategory_id,
s.title,
c.title,
c.id,
COUNT(ptc.catid)
FROM supercategories s,
supercategories_to_categories stc,
categories c,
products p,
products_categories ptc
WHERE c.viewable='1'
AND c.id=stc.category_id
AND stc.supercategory_id=s.supercategory_id
AND ptc.catid=c.id
AND ptc.productid = p.id
AND p.viewable='y'
GROUP BY ptc.catid
ORDER BY s.title, c.title
Thanks!