I have this SQL:
SELECT itemId, parentId, value FROM item ORDER BY value DESC
which correctly returns:
+--------+------------------+
| itemId | parentId | value |
+--------+------------------+
| 1 | 5 | 500 |
| 4 | 1 | 500 |
| 2 | 5 | 10 |
| 5 | 1 | 10 |
| 3 | 5 | 0 |
| 6 | 1 | 0 |
+--------+----------+-------+
I tried adding "GROUP BY parentId", but this seems to pick two random items, ignoring the ORDER BY clause:
+--------+------------------+
| itemId | parentId | value |
+--------+------------------+
| 2 | 5 | 10 |
| 6 | 1 | 0 |
+--------+----------+-------+
What SQL should I use to return only the item with the highest value for each parentId?:
+--------+------------------+
| itemId | parentId | value |
+--------+------------------+
| 1 | 5 | 500 |
| 4 | 1 | 500 |
+--------+----------+-------+