I have a table with products that have id price category etc... I am trying to extract 1 item from each item_category, which is the most recent one (has the highest ID amongst its own category).
Here is the code, it gets me 6 items from 6 categories but they are the oldest (with the smallest ID)
SELECT * from items WHERE item_category = '2' or item_category = '4' or
item_category = '12' or item_category = '13' or item_category = '14' or
item_category = '19' GROUP BY `item_category` ORDER BY `item_id` LIMIT 6
Order by ID is executed on the returned array of 6 items, and no on the original table.
How can I exctract the newest items instead?
the best query i think
select *
from items
where item_category in ("2","4","12","13","14","19")
group by item_category
order by item_category DESC