I have an online store, and the products database is setup like below. What I want to do is to form a query that will print main categories and number of products inside them, ordered by fewest to most products. Is that possible without doing multiple queries?
Result should be like this:
maincat products
melons 0
grapes 2
apples 4
Databases:
database: maincat
id name
1 apples
2 grapes
3 melons
database: subcat
maincat_id subcat_id name
1 1 yellow apples
1 2 green apples
2 3 normal grapes
3 4 watermelons
3 5 honeydew melon
database: products
subcat_id name
1 yellow apple 1
1 yellow 2
1 yellow 3
2 green apple 1
3 grape 1
3 grape 2