I have a table with columns Id,DoucmentId,Name,Created,MinorVersion,MajorVersion
with example data :
GUID,1,'document1',GETDATE(),1,0)
GUID,1,'document1',GETDATE(),2,0)
GUID,1,'document1',GETDATE(),1,1)
GUID,2,'document2',GETDATE(),1,0)
In query i need get all unique with higest major and minor version :
GUID,1,'document1',GETDATE(),1,1)
GUID,2,'document2',GETDATE(),1,0)
I have this query, but i need return all column in table…
SELECT DISTINCT
DocumentId,
MAX(MajorVersion),
MAX(MinorVersion)
FROM ComDoc_Document
GROUP BY(DocumentId)
Is here some trick to get this?
Thanks for help
EDIT : My configuration is MSSQL 2008R2 standart
this also has the advantage that if you later decide to retrieve the last two revisions for each document, you just do
WHERE RANK <= 2