I have a table in mysql like this:
+----+------+-----------+----+----+-----+
| id | vers | doc | pr | dd | f |
+----+------+-----------+----+----+-----+
| 1 | 1 | doc1.pdf | 1 | 1 | neg |
+----+------+-----------+----+----+-----+
| 2 | 1 | other.pdf | 1 | 3 | pos |
+----+------+-----------+----+----+-----+
| 3 | 1 | bo.pdf | 1 | 6 | ok |
+----+------+-----------+----+----+-----+
| 4 | 2 | doc2.pdf | 1 | 1 | pos |
+----+------+-----------+----+----+-----+
As you can see, the rows with id 1 and 4 have the same pr
and dd
value, but with a different vers
.
I want retrieve all rows and if I have more rows with the same pr
and dd
I want get only the row with the maximum value inside the vers
column.
So in this example, I want the row with id 2, 3 and 4.
Can I do that using an SQL query? If yes, how?