Possible Duplicate:
mysql: Using LIMIT within GROUP BY to get N results per group?
I have a two tables:
- Items
- Categories
Each item belongs to a category. What I want to do is select 5 items per category but say 20 items in total.
SELECT
item_id, item_name, items.catid
FROM
items, categories
WHERE
items.catid = categories.catid
GROUP BY items.catid LIMIT 0,5 //5 per category group
Edit: if there are more than 5 items per category – they should be ordered by the item_id (numeric value)
Try this query –
It will show first 5 items per category. Uncomment
LIMIT 20if you need. JoinCategoriestable if you need.