I have two tables as shown below :
Table Name : scores
+-------+-----------+--------------+-----------+
| UNID | name | score | PRID |
+-------+-----------+--------------+-----------+
| 1 | name_1 | 93 | 1 |
| 2 | name_2 | 71 | 1 |
| 3 | name_3 | 53 | 2 |
| 4 | name_4 | 82 | 2 |
| 5 | name_5 | 31 | 2 |
| 6 | name_6 | 68 | 3 |
+-------+-----------+--------------+-----------+
And
Table Name : user_dir
+-------+-----------+--------------+-----------+
| PRID | fname | city | gender |
+-------+-----------+--------------+-----------+
| 1 | fname1 | XX | m |
| 2 | fname2 | YY | f |
| 3 | fname3 | ZZ | f |
+-------+-----------+--------------+-----------+
For any given PRID from user_dir, how can I get the entire row that corresponds to the highest value of score for that PRID?
As an example, for the user "fname2" with a PRID of 2, I want to pull this entire row (and not just the value of score) as follows :
+-------+-----------+--------------+-----------+
| UNID | name | score | PRID |
+-------+-----------+--------------+-----------+
| 4 | name_4 | 82 | 2 |
I tried this using the "max" function of that row, but it instead gives me the first row found with that PRID, along with the correct (max) value of score, as follows :
+-------+-----------+--------------+-----------+
| UNID | name | score | PRID |
+-------+-----------+--------------+-----------+
| 3 | name_3 | 82 | 2 |
EDIT : I misunderstood my requirement, the final result needed to have the corresponding "name" value for the highest score, not the highest score itself.
So the actual final result would be :
+-------+-----------+--------------+-----------+
| PRID | name | fname | score |
+-------+-----------+--------------+-----------+
| 1 | fname1 | name_1 | 93 |
| 2 | fname2 | name_4 | 82 |
| 3 | fname3 | name_6 | 68 |