I have 2 tables: x_products
and x_category
I have to select the last 3 products inserted (order by x_products.data
column, descending) for each category using a single query.
My idea was to use an INNER JOIN
technique (for using a single query).
I've tried to use LIMIT 0,3
, but only the last 3 products are returned (3 per total, but not for each category.
SELECT products.*
FROM x_products products
INNER JOIN x_category categories
ON products.category = categories.id
ORDER BY products.data DESC LIMIT 0,3
How could I select 3 products for each category, but not 3 products per total?