sql >> Base de Datos >  >> RDS >> Sqlserver

Consulta SQL - Obtener la revisión más reciente

La consulta a continuación funcionará independientemente de cualquier relación entre ProjectRevId y 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