title: SQL Server find most recent date range
body: <p>I have a <code>tableA</code> of date ranges:</p>
  
  <pre><code>tranid    item    startdate     enddate
  ---------------------------------------
  1          A      1/1/2000      2/2/2005
  2          A      5/1/2000      2/2/2005
  3          B      7/8/2015      9/8/2015
  4          C      4/10/2007     7/20/2008
  5          C      4/10/2003     7/20/2005
  </code></pre>
  
  <p>How to write a SQL query to only select the most recent transactions (ex the most recent start and end dates)?  </p>
  
  <p>For example, for A, the most recent date range is 5/1/2000 to 2/2/2005 and for C, the most recent date range is C 4/10/2007 to 7/20/2008.  </p>
  
  <p>I am at a complete loss to write this because it seems easy but is not. </p>
  
  <pre><code>select item, max(enddate), max(startdate)
  from tableA 
  where max(enddate)
  group by item, enddate, startdate
  </code></pre>
  
  <p>SQL Server returned an error related to 'having' on something like that - a problem with aggregates.</p>
  
  <p>gracias :)</p>