# Find x items in each category

**URL:** <https://www.ruby-forum.com/t/find-x-items-in-each-category/128930>\
**Category:** Rails\
**Created:** [February 12, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/find-x-items-in-each-category/128930 "2008-02-12T19:45:06Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![farfignugen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/f17d59/32.png) [@farfignugen](https://www.ruby-forum.com/u/farfignugen)\
**Post date:** [February 12, 2008, 7:45pm UTC](https://www.ruby-forum.com/t/find-x-items-in-each-category/128930/1 "2008-02-12T19:45:06Z")

</div>

I am trying to figure this out, but haven’t had much luck searching the  
forums here or google.

I have categories and items. My category model has many items, items  
belong to categories, etc.  
I can’t figure out how to do a find in my controller that will give me  
the 5 newest items in each category.  
My items table has created\_at, I know how do sort on that and use :limit  
=\> 5, but I am not sure how to do it for each category. I feel like I  
should do a Categories.find(:all) then something with each.do but I  
don’t know what.

I think I could just find all of the items, then .select (for each  
category) but then I have wait while I retrieve all of the items, when I  
really only want a few of them.

Any ideas, or a link to a tutorial or screencast would be really  
appreciated. I feel like this is something really basic, but I can’t  
figure it out today.
