I have a categories table which lists about 35 possible categories. I then also have an Item table where one of the foreign keys relates back to a category in the categories table. On my index page I’m looking to just show how many items are in each category. I’m just unsure what the best way to go about this is, in terms of building a more efficient query and reducing the number of calls to the DB.
Any thoughts would be great
Thanks
You are looking for a simple aggregation query:
The
left outer joingets all categories, even if they do not have any items.