Hiho, i got following table:
+----+----+-------+----------+
| p1 | p2 | value | position |
+----+----+-------+----------+
| 1 | 5 | 0 | 1 |
| 1 | 6 | 0 | 2 |
| 1 | 7 | 0 | 3 |
| 1 | 7 | 1 | 4 |
| 1 | 8 | 1 | 5 |
+----+----+-------+----------+
as result of a query in need exactly this result:
+----+----+-------+----------+
| p1 | p2 | value | position |
+----+----+-------+----------+
| 1 | 5 | 0 | 1 |
| 1 | 6 | 0 | 2 |
| 1 | 7 | 1 | 4 |
| 1 | 8 | 1 | 5 |
+----+----+-------+----------+
As you will notice the dateset with the same p1 and p2 combination must be grouped, but i need the dataset with the highest position value. This behavior must be guaranteed.
I have tried something like:
SELECT *
FROM table
GROUP BY p1, p2
HAVING MAX(position)
without a proper result. Does anyone have an idea?