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! :slight_smile:

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: