Stanni
Stanni

Reputation: 747

Finding record in mysql table that has the highest value

I want to be able to seach in my table named "map" to see which record has the highest value for "positionV".

For example if I had 5 records in "map" table and under "positionV" the values for each were, "3, 8, 9, 2, 10" I would wont it to output 10.

I am using PHP also by the way.

Upvotes: 1

Views: 5439

Answers (3)

DBunting
DBunting

Reputation: 38

wouldnt

SELECT * FROM `map` WHERE 1 ORDER BY `positionV` DESC LIMIT 1

be sufficient?

whats the resource weight of the various methods given, anyone know?

Upvotes: 0

Gumbo
Gumbo

Reputation: 655599

Try this:

SELECT *
FROM map
WHERE positionV = (SELECT MAX(positionV) FROM map)

Upvotes: 9

Graveen
Graveen

Reputation:

SELECT * FROM map WHERE condition HAVING positionV = MAX(positionV)

Better to use having when doing aggregates.

Upvotes: 1

Related Questions