I’m making a sitemap. I have a table, which connects posts with categories (2 columns: categoryId, postId). There are nearly 9000 categories in total, and I want to count number of posts in each category to predict number of pages in pagination. I tried to do 9000 COUNT(*)’s for each category, but that is too slow (2 hours, actually). What can I do? Thanks.
Share
You just have to do a SELECT COUNT and GROUP it by your categoryid like this :
If you want only for a specific category, try to use
WHERE categoryID = ?before the
GROUP BY