Hi Everybody I have a table called mail which is as follows: id user_id message_id conversation_id created_at == ===== ========= =========== ================22 2 12 10 2008-07-17 18:18:38 23 3 12 10 2008-07-17 18:18:39 24 1 12 10 2008-07-17 18:18:39 25 2 13 10 2008-07-17 18:29:16 26 1 13 10 2008-07-17 18:29:16 27 3 13 10 2008-07-17 18:29:17 28 1 14 11 2008-07-17 19:23:09 29 3 14 11 2008-07-17 19:23:10 30 2 14 11 2008-07-17 19:23:09 Now i want only those unique tuples whose conversation_id are same but out of it I want the latest i.e order by created_at desc. but I want all attributes. This is what I want for as an output =========================id user_id message_id conversation_id created_at == ===== ========= =========== ================27 3 13 10 2008-07-17 18:29:17 29 3 14 11 2008-07-17 19:23:10 --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
U can do like. conversation_ids << [10,11] for conversation in conversation_id @my_mail << Mail.find(:last,:conditions => [''conversation_id=?'',conversation]) end i hope it will work :) On Fri, Jul 18, 2008 at 11:22 AM, mrbless <mrbless-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Hi Everybody I have a table called mail which is as follows: > > > id user_id message_id conversation_id created_at > == ===== ========= =========== ================> 22 2 12 10 > 2008-07-17 > 18:18:38 > 23 3 12 10 > 2008-07-17 18:18:39 > 24 1 12 10 > 2008-07-17 18:18:39 > 25 2 13 10 > 2008-07-17 18:29:16 > 26 1 13 10 > 2008-07-17 18:29:16 > 27 3 13 10 > 2008-07-17 18:29:17 > 28 1 14 11 > 2008-07-17 19:23:09 > 29 3 14 11 > 2008-07-17 19:23:10 > 30 2 14 11 > 2008-07-17 19:23:09 > > > Now i want only those unique tuples whose conversation_id are same but > out of it I want the latest i.e order by created_at desc. but I want > all attributes. > This is what I want for as an output > =========================> id user_id message_id conversation_id created_at > == ===== ========= =========== ================> 27 3 13 10 > 2008-07-17 18:29:17 > 29 3 14 11 > 2008-07-17 19:23:10 > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
thank for your reply. I resolved it in the similar fashion. On Jul 18, 11:09 am, "bala kishore pulicherla" <balumc...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> U can do like. > > conversation_ids << [10,11] > for conversation in conversation_id > @my_mail << Mail.find(:last,:conditions => > [''conversation_id=?'',conversation]) > end > > i hope it will work :) > > On Fri, Jul 18, 2008 at 11:22 AM, mrbless <mrbl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > Hi Everybody I have a table called mail which is as follows: > > > id user_id message_id conversation_id created_at > > == ===== ========= =========== ================> > 22 2 12 10 > > 2008-07-17 > > 18:18:38 > > 23 3 12 10 > > 2008-07-17 18:18:39 > > 24 1 12 10 > > 2008-07-17 18:18:39 > > 25 2 13 10 > > 2008-07-17 18:29:16 > > 26 1 13 10 > > 2008-07-17 18:29:16 > > 27 3 13 10 > > 2008-07-17 18:29:17 > > 28 1 14 11 > > 2008-07-17 19:23:09 > > 29 3 14 11 > > 2008-07-17 19:23:10 > > 30 2 14 11 > > 2008-07-17 19:23:09 > > > Now i want only those unique tuples whose conversation_id are same but > > out of it I want the latest i.e order by created_at desc. but I want > > all attributes. > > This is what I want for as an output > > =========================> > id user_id message_id conversation_id created_at > > == ===== ========= =========== ================> > 27 3 13 10 > > 2008-07-17 18:29:17 > > 29 3 14 11 > > 2008-07-17 19:23:10--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---