i have table and column id, and the values are 1, 2 ,3,…,10,11,12,13.
how to query get max id from varchar type ? i had try
select MAX(id) from table
but the result is 9, Please help ??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Looks like the values are strings and it selecting the maximum string. You have to cast them to numbers first if you want them to sort numerically. You can use CONVERT to do this:
You can also use CAST:
They do nearly the same thing except
CONVERThas some additional options if you need them.