HKL9 (string) is larger than HKL15 because they are compared as strings. One way to solve your problem is to define a column function that returns only the numeric part of the account number.
If all account numbers start with HKL , you can use:
SELECT MAX(CAST(SUBSTRING(invoice_number, 4, length(invoice_number)-3) AS UNSIGNED)) FROM table
The number invoice_number is required, excluding the first 3 characters, is converted to int and selects max from it.
nakosspy
source share