I have 3 tables: product, category and product_category (which products are in each category).
I'd like to get the top 3 most expensive product in each category.
I have this basic relation:
select c.name
, p.id
, p.price
from category c
left
join product_category pc
on pc.category_id = category.id
left
join product p
on pc.product_id = p.id
But now I would like to get just the 3 most expensive of each category.
In this case we can use any number of joined tables and it can be escalated to any more complex query.
Is this possible without a loop ?
I'm using 10.2.14-MariaDB-log with this schema http://sqlfiddle.com/#!9/43035a