Hi, I have a Rating table in my SQL database and I would like to return the row containing the highest average rating where the picture_id for that row is a certain value. I could do this by SQL but I''d like to use the Ruby functions if it''s possible. I can get the maximum value of rating like this: @rating = Rating.maximum(:rating, :conditions => [''picture_id = ?'', @picture_id]) which works great but only returns the maximum value for the column "rating" when I want the whole row of values for the record with the maximum rating. The SQL would be something like this: SELECT user_id, picture_id, max(rating) FROM ratings WHERE picture_id ? GROUP BY user_id, picture_id'', @picture_id] I''ve not tested that but you get the idea... So is there anyway of running the above SQL using a ruby function ? Thanks for any help Phil -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---