← Tutti gli articoli

How-To Update Tables Using Inner Joins and Group By

05 March 2011  ·  TSQL · Recipe  ·  158 visite

I'm making an update to my table Contents and would like to update the ContentDate coloumn in all the rows that have the minimum BeginDate in the ContentsHistory table.

UPDATE c
  SET c.ContentDate = hh.NewDate
  
  FROM
  Contents as c 
  INNER JOIN 
  (Select ContentId, MIN(BeginDate) as NewDate from ContentsHistory group by ContentId ) as hh
  
  on c.ContentId = hh.ContentId
Si è verificato un errore imprevisto. Ricarica

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.