Reputation: 23542
SELECT id, uid, MAX(a) FROM table GROUP BY uid
Now, the id is from a random/first row.
How do I get id for the maximum value?
Upvotes: 0
Views: 105
Reputation: 224
If you just want to get the maximum value for id just use Max(id).
SELECT MAX(id), uid, MAX(a) from table GROUP BY uid;
Upvotes: 0
Reputation: 18584
I'd try this:
SELECT id, uid, a FROM table1 ORDER BY a DESC LIMIT 1
Upvotes: 1
Reputation: 33502
select id, uid from table1 where a=(select max(a) from table1)
Of course, this will fail if you have multiple max values that are the same.
Upvotes: 1