title: Updating multiple rows using a subquery in SQL
body: <p>I have a summary table return data from a master table. I am trying to update some of the summary data from values in the master table as such:</p>
  
  <pre><code>update #summary
    set TopSpeed = CD.TopSpeed, SpeedTime = CD.TimeSent, SpeedDriver = CD.Driver
  from
  (
    select top 1 TopSpeed, TimeSent, Driver
    from CarData
    where CarData.VehicleId = #summary.VehicleId 
    and CarData.TimeSent between #summary.Start and #summary.Stop
    order by CarData.TopSpeed desc, TimeSent desc
  ) as CD
  </code></pre>
  
  <p>The #summary temporary table is creating summarised data about trips undertaken by a car. There can be multiple trips for each car with each trip having a start and stop time. The CarData table contains all the detailed car data like speed and position etc.</p>
  
  <p>Please can you help?</p>
  
  <p>Thanks,
  Robert</p>