Sqlserver
 sql >> Datenbank >  >> RDS >> Sqlserver

SQL-Abfrage - Neueste Version abrufen

Die folgende Abfrage funktioniert unabhängig von einer Beziehung zwischen ProjectRevId und 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