Order By Varchar that Contain Int

For example if I have this data set:


B-1
B-2
B-11
B-22
B-100
BA-1

Normal if you sort by field_name ASC the result will be :


B-1
B-11
B-100
B-2
B-22
BA-1

The solution that i found after searching all over the place is :

ORDER BY LENGTH( field_name ) , field_name

It will fix the order contain integer in it.

Leave a Reply

Your email address will not be published. Required fields are marked *