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
Post a Comment