use the limit and orderby in your find statement this may not be exact but
its close
@posts =Blog.finda(:all, :order=>''created_on DESC'',
:limit=>''3'')
something like that
On 9/10/05, Justin Bailey
<jgbailey-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:>
> I''m developing blog software using ruby & rails, but this is
really a
> SQL question. I have two tables - blogs and posts. A given row in the
> posts table will belong to one blog, and there are many posts per
> blog. Each posts row has a date_posted row, also.
>
> Now, my question. What would the SQL look like to select the 5 most
> recent posts for each blog? That is, for each row in blogs, I would
> like to get the 5 most recent related rows from the posts table.
>
> Here''s what makes it a guru question - how do I do that in one
query?
> Thanks all!
>
> Justin
> _______________________________________________
> Rails mailing list
> Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails