John Kopanas
2006-Dec-29 21:01 UTC
After Two Queries Are Returned Merge Them and Order Them
I am using mySQL. I run two different finds and once I get them both back I want to merge the results and order them? What is the best way to go about this? Thanks for your help! :-) -- John Kopanas john-Iau1QiYlxLpBDgjK7y7TUQ@public.gmane.org http://www.kopanas.com http://www.cusec.net http://www.soen.info --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Jon Garvin
2006-Dec-29 21:12 UTC
Re: After Two Queries Are Returned Merge Them and Order Them
Assuming that you''re not mixing results of two different classes (apples and oranges).. @all_apples = @first_apples + @second_apples @sorted_apples = @all_apples.sort { |a,b| a.sortable_value <=> b.sortable_value } But, I would strongly recommend investigating the possibility of doing it all in one sql call. You''ll find it much faster, especially if you''re dealing with a ton of apples. find_by_sql may be your only option in that regard, but it might be worth it. If you''re only dealing with a bushel of apples each time, then the above may be sufficient. John Kopanas wrote:> > I am using mySQL. I run two different finds and once I get them both > back I want to merge the results and order them? What is the best way > to go about this? > > Thanks for your help! :-) >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---