I have this scenario in my application: a database with 4 main tables. They are:
brands
categories
categories_to_product
products
Between brands table and products table there is a one to many relation. Of course, there is a join field in products table that let me to relate the two tables named brand_id.
Between categories table and products table there is a many to many relation, and both tables use the categories_to_product table for to have the many to many relation. In the join table there is a composed PK with two fields, category_id and product_id.
So far so good.
Now, my goal is to have some statistics, and this is a field too difficult for my sql knowledge.
I'd like to achieve this kind of data:
- the first ten brands with more products related
- the first ten categories with more products related
I neither know from where I have to start, can someone tell me in what direction do I Have to go for to start?
Thank you in advance.
Giorgio.