On Oct 10, 9:57 pm, "Abhishek shukla"
<bettera...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hello friends,
> i need to get the latest record of same field
> for e.g
>
> there is a table called xyz and it contains the following field item_id,
> created_at
>
> so i want a single record for every similar item_id whose created_at is the
> latest.
>
> i tried group by with order by but no success, Please help me with proper
> query.
>
> Thanks
> Abhi
Xyz.maximum(:created_at, :group => :item_id)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---