I have a table for contents on a page. The page is divided into sections.
I want to get the last version for each page-section.
Id (int)
Version (int)
SectionID
Id Version SectionID Content 1 1 1 AAA 2 2 1 BBB 3 1 2 CCC 4 2 2 DDD 5 3 2 EEE
I want to get:
Id Version SectionID Content 2 2 1 BBB 5 3 2 EEE
You could use an exclusive self join:
The
wherestatement basically says: where there is no newer version of this row.Slightly more readable, but often slower, is a
not existscondition: