title: Selecting minimum date in data set
body: <p>I have a data set that i am attempting to select the first record with a station id of 2.</p>
  
  <pre><code>InspectionNbr   Station          DateTimeStamp
  825065             1            2010-11-16 04:38:49.000
  825065             2            2010-11-16 12:38:31.000
  825065             2            2010-12-06 01:35:14.000
  825065             2            2011-01-24 08:11:04.000
  </code></pre>
  
  <p>In this case i want to select the second line of the results. How can i use SQL to get the minimum date where stationid = 2?</p>
  
  <p>That being stated, this is what i have.
  i created a temporary table in SQL. i have it setup to populate the table with the latest date. Then i attempt and update the temporary table with the following code</p>
  
  <pre><code>UPDATE @report_out 
   set    
  DateTimeStamp = Min(si.CreatedDate)
   from
  @report_out as r
   INNER JOIN
  StationInspection as si
      on si.ModifiedDate = r.DateTimeStamp
  where
  r.Station = 2
  </code></pre>
  
  <p>For some reason beyond me it doesn't like the DateTimeStamp = Min(si.CreatedDate)
  i get the follwing error:
  An aggregate may not appear in the set list of an UPDATE statement.</p>
  
  <p>any pointers?</p>