sql - Select MAX INT value of TEXT column -


userid    username  password  1                abc               123 10               xyz               456 3                mno               254  select max(userid) userid userlogin 

when run query gives me 3 instead of 10

all columns text datatype

your query returning 3 because larger value considering lexicographic order (anything starting 3 considered greater starting 1, starting b greater starting a).

use val function convert text columns numeric values:

select max(val(userid)) userid userlogin 

if you're concerned performance, should make column numeric, though. take account you're calling function every row in table. also, won't using indexes column may have.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -