I have a database of items. Each item is categorized with a category ID from a category table. I am trying to create a page that lists every category, and underneath each
Recently I came across a similar situation, I tried a query that worked for me which is independent on database
SELECT i.* FROM Item AS i JOIN Category c ON i.category_id=c.id WHERE
(SELECT count(*) FROM Item i1 WHERE
i1.category_id=i.category_id AND
i1.date_listed>=i.date_listed) <=3
ORDER BY category_id,date_listed DESC;
It is equivalent to running 2 for loops and checking if items newer than this are less than 3