I have 2 tables: categories and items.
table: categories
id | parent_id | name
------------------------------
1 | 0 | drinks
2 | 1 | soft drinks
3 | 1 | beer
and
table: items
id | category_id | name
----------------------------
1 | 1 | water
2 | 2 | coca cola
3 | 2 | pepsi cola
4 | 3 | stella artois
What I want to do? I want to count all the items in a category or in a subcategory of that category.
So if I select for the category "drinks" I want to count all the items in the category "drinks" but also all the items in the subcategories "soft drinks" and "beer".
I think it has something to do with a left join but I cannot figure it out.
Thanks in advance!