ActiveRecord nested SELECT — can I do it without manual SQL?
问题 I have a table with (among other things) a name and a rank. I'd like to return the set of all unique names, but for each name returned, I'd like to pick the row with the highest rank. This is simple with two nested SELECT statements: SELECT * FROM (SELECT * FROM foo ORDER BY rank DESC) AS ordered GROUP BY name MySQL takes the first "hit" for each name, which (because of the earlier ORDER BY) will always be the highest-ranking one. Now, if I want to wire into this table with ActiveRecord, I'm