I have a table like this:
// mytable
+----+----------+--------------+
| id | user_id | reputation |
+----+----------+--------------+
| 1 | 442 | 1000 |
| 2 | 746 | 500 |
| 3 | 843 | 800 |
| 4 | 746 | 700 |
| 5 | 442 | 300 |
+----+----------+--------------+
Here is my query:
select user_id, min(reputation) min_rep
from mytable
group by user_id
And here is the result:
+---------+---------+
| user_id | min_rep |
+---------+---------+
| 442 | 300 |
| 746 | 500 |
| 843 | 800 |
+---------+---------+
Now I need to select the id
of that row. So here is the expected result:
+----+---------+---------+
| id | user_id | min_rep |
+----+---------+---------+
| 5 | 442 | 300 |
| 2 | 746 | 500 |
| 3 | 843 | 800 |
+----+---------+---------+
Any idea how can I do that?