I have a table with the following basic structure.
unique_id | name | original | version
-----------------
1 | a1 | 1 | 1
2 | b1 | 2 | 1
3 | a2 | 1 | 2
4 | a3 | 1 | 3
5 | c1 | 5 | 1
6 | b2 | 2 | 2
Now it should be obvious from this that there is a form of version control, where we keep track of the original document, and also track the version of the current document.
If I want to get the latest version of a particular document I do something like the following.
SELECT * FROM table WHERE original = (SELECT original FROM table WHERE id = 3) ORDER BY version DESC
My question is, how do I do get a list of all of the most recent versions in the table with only one query?