 <p><code>HKL9</code> (string) is greater than <code>HKL15</code>, beacause they are compared as strings. One way to deal with your problem is to define a column function that returns only the numeric part of the invoice number.</p> <p>If all your invoice numbers start with <code>HKL</code>, then you can use:</p> <pre><code>SELECT MAX(CAST(SUBSTRING(invoice_number, 4, length(invoice_number)-3) AS UNSIGNED)) FROM table </code></pre> <p>It takes the invoice_number excluding the 3 first characters, converts to int, and selects max from it.</p>