SQL: Select all distinct and pick the row that has the max value in another column

74 Views Asked by At
| nid | vid | max_score |
|-----+-----+-----------|
|  1  |  1  |     1     |
|-----+-----+-----------|
|  1  |  2  |     1     |
|-----+-----+-----------|
|  2  |  1  |     1     |
|-----+-----+-----------|
|  2  |  2  |     2     |
-------------------------

I would like to select only the distinct nid, but also only take the row where the vid is the highest.

So the result here would give me

1, 2, 1

2, 2, 2

0

There are 0 best solutions below