Rails db query uniq column value and max value <p>I need to query db unique values and maximum value of another column.</p> <p>For example:</p> <pre><code>:name =&gt; "some_name_1", :version =&gt; 10, :other_columns... :name =&gt; "some_name_1", :version =&gt; 11, :other_columns... :name =&gt; "some_name_2", :version =&gt; 15, :other_columns... :name =&gt; "some_name_3", :version =&gt; 18, :other_columns... </code></pre> <p>What I would need is if the name show up multiple times the query should return only the one with the last version ( higher version number )</p> <p>So it should look like this : </p> <pre><code>:name =&gt; "some_name_1", :version =&gt; 11, :other_columns... :name =&gt; "some_name_2", :version =&gt; 15, :other_columns... :name =&gt; "some_name_3", :version =&gt; 18, :other_columns... </code></pre> <p>note that <code>:name =&gt; "some_name_1", :version =&gt; 10, :other_columns...</code> those not show in the query because a record with the same name already exist with a hither version number.</p> <p>Any idea? </p>