title: Update using MIN
body: <p>I have two tables.</p>
  
  <pre><code>TableA
  
      Userid  Starttime               reason
      John    yyyy-mm-dd hh:mm:ss     logged in
  
  Table B
  
      Userid  Date            Starttime              reason
      John    yyyy-mm-dd    yyyy-mm-dd hh:mm:ss     logged in
  </code></pre>
  
  <p>I need to update the starttime of table B with min(a.starttime) while a.Userid = b.userid, a.starttime = b.date, and reason = 'logged in'.</p>
  
  <p>I seem to be having issues with using Min(a.starttime) as what I want to use to update.</p>
  
  <p>My query is below:</p>
  
  <pre><code>update B
  set B.starttime = (
    select Min(A.Starttime)
    from table as A
    where B.UserID = A.UserID
    and (CONVERT(DATETIME,A.DATE,102)) = (CONVERT(DATETIME,B.Date,102)))
    and  (A.Reason = 'loggedin')
  )
  from table2 as B
  </code></pre>
  
  <p>I convert the dates since table B has the date as for example 2011-09-13 00:00:00 and A has the date and times.</p>