Table in SQL:
Document Revision Version
-----------------------------------------------------
ABC 1 1
ABC 1 2
ABC 1 8
ABC 2 3
DocumentF 1 3
DocumentF 1 2
Expected output:
Document Revision Version
-----------------------------------------------------
ABC 1 8
ABC 2 3
DocumentF 1 3
Basically if there are two versions of the same revision, bring back the latest based on version.
I've tried the following:
var list = from document in documents
group document by document.Document
into groups
from g in groups
group g by g.Revision
into final
select final.OrderByDescending(d => d.Version).FirstOrDefault();
The above code produces the following:
Document Revision Version
-----------------------------------------------------
ABC 2 3
DocumentF 1 3