 <p>This isn't really an aggregation, it's just a groupwise maximum. <code>ROW_NUMBER</code> is the easiest way to write these queries:</p> <pre><code>;WITH CTE AS ( SELECT Query, CreatedTime, UpdatedTime, &lt;other_columns&gt;, ROW_NUMBER() OVER ( PARTITION BY Query ORDER BY CreatedTime DESC, UpdatedTime DESC ) AS RowNum FROM Somethings WHERE CreatedTime &gt;= '20100101' AND CreatedTime &lt; '20100201' ) SELECT * FROM CTE WHERE RowNum = 1 </code></pre> <p>It's not necessarily the most efficient, but it's reasonably good in most cases. And the nice thing is that you can modify this to do top 2 per group, top 3, etc., and you have complete control over ties.</p> <p>(P.S. I hope you don't actually name the column "Query")</p>