Reputation: 117
I want to get the highest value from a column of a MySQL Table:
example:
Code (PK) | ...
AT10000
DE10001
FR10002
How I can get the Value "10002"?
Upvotes: 0
Views: 99
Reputation: 3576
If you want to get the entire row corresponding to the max value, try this:
SELECT TOP 1 *
FROM yourTable T
ORDER BY SUBSTRING(T.code, 3) DESC
Or you also can use this one:
SELECT *
FROM yourTable T
WHERE SUBSTRING(T.code, 3) = (SELECT MAX(SUBSTRING(T2.code, 3)
FROM yourTable T2)
And this last one if you just want to have the max value without info about the row:
SELECT MAX(SUBSTRING(T.code, 3) AS [value]
FROM yourTable T
Hope this will help you.
Upvotes: 0