PiTheNumber
PiTheNumber

Reputation: 23542

id for MAX value

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

Answers (3)

Usman Tiono
Usman Tiono

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

Matteo Tassinari
Matteo Tassinari

Reputation: 18584

I'd try this:

SELECT id, uid, a FROM table1 ORDER BY a DESC LIMIT 1

Upvotes: 1

Fluffeh
Fluffeh

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

Related Questions