I need to retrieve an sql MAX result from a table with a varchar column like this "MYNAME-0xxxxx" or "MYNAME-xxxxx" (a fixed string followed by a minus followed by 6 digits starting with zero OR 5 digits starting by a non zero)
I tried this:
SELECT MAX( substring( myColumn , locate('-', myColumn) ) )
FROM MyTable
With this statement I am able to achieve the maximum number of all column value in this form "MYNAME-xxxx" but it does not apply on the columns like "MYNAME-0xxxxx)
let'say we have
JOHN-12345
JOHN-12346
JOHN-012347
I want my result be "012347" but my code return me "12346". Seems to me that MAX value between 12346 and 012347 in sql is 12346. Please note that number are incremented so if we start from 012347 we can reach 999999