Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

Query SQL - Ottieni la revisione più recente

La query seguente funzionerà indipendentemente da qualsiasi relazione tra ProjectRevId e DateCreated.

SELECT *
FROM ProjectRevisions
INNER JOIN (
  SELECT ProjectId
    , MAX(DateCreated) AS DateCreated
  FROM  ProjectRevisions
  GROUP BY ProjectId
  ) AS CurrentRevision
  ON CurrentRevision.ProjectId = ProjectRevisions.ProjectId
  AND CurrentRevision.DateCreated = ProjectRevisions.DateCreated