firepages
08-31-2004, 08:22 AM
I should not be using varchar here I know but I am stuck with it for now..
I have a varchar which mostly stores a serial number [0-9]{1-9} , but sometimes stores an alphanumeric flag 'R' or 'S' etc , I want to be able to suggest the next available serial number , which is basically MAX(um_serial) + 1 , but since its not an integer field max does not work , I currently have ..
SELECT um_serial
FROM user_machines
WHERE um_serial
REGEXP "^[0-9]{2,}" /*using 2 as the minimum as '1-9 are long gone and it avoids catching '0'*/
this does return only the numeric fields , but short of a temporary table , or fetching all of the results and sorting them in PHP , can I/how can I, now select the 'max' value in the same query ?
I have a varchar which mostly stores a serial number [0-9]{1-9} , but sometimes stores an alphanumeric flag 'R' or 'S' etc , I want to be able to suggest the next available serial number , which is basically MAX(um_serial) + 1 , but since its not an integer field max does not work , I currently have ..
SELECT um_serial
FROM user_machines
WHERE um_serial
REGEXP "^[0-9]{2,}" /*using 2 as the minimum as '1-9 are long gone and it avoids catching '0'*/
this does return only the numeric fields , but short of a temporary table , or fetching all of the results and sorting them in PHP , can I/how can I, now select the 'max' value in the same query ?