I'm stuck with the SQL query, the idea is that I have a database where I keep all the documents with every document version(revisionNumber)
etc. What I want to achieve is that I want to access currently only those documents with the latest revisionNumber
.
| id | title | documentForm | revisionNumber | effectiveDate |
| --: | ------------------- | -------------| -------------: | :------------ |
| 1 | Event Calendar | SOP-CL | 1.0 | 2011-02-02 |
| 2 | Event Calendar | SOP-CL | 2.0 | 2012-12-16 |
| 3 | Event Calendar | SOP-CL | 3.0 | 2014-02-15 |
| 4 | Event Calendar | SOP-CL | 4.0 | 2014-08-01 |
| 5 | Event Calendar | SOP-CL | 5.0 | 2016-09-12 |
| 6 | Event Calendar | SOP-CL | 6.0 | 2018-09-11 |
| 7 | Software development| SOP-DEV | 1.0 | 2015-11-25 |
| 8 | Granting and... | SOP-GRA | 1.0 | 2014-08-04 |
| 9 | Granting and... | SOP-GRA | 2.0 | 2015-12-07 |
| 10 | Granting and... | SOP-GRA | 3.0 | 2018-03-26 |
And here you can see the result I need to get after query:
| id | title | documentForm | revisionNumber | effectiveDate |
| --: | ------------------- | ------------ | -------------: | :------------ |
| 6 | Event Calendar | SOP-CL | 6.0 | 2018-09-11 |
| 7 | Software development| SOP-CL | 1.0 | 2015-11-25 |
| 3 | Granting and... | SOP-GRA | 3.0 | 2018-03-26 |
I've been searching in google and found that it can be done by grouping - for example - documentForm and returning MAX(revisionNumber)
but I don't get the correct row id
and effectiveDate
. I guess I just don't use them right.