MYSQL Trick – ORDER STRING AS NUMBER

Sometimes you have to store numbers in text format. This is not a good practice, but sometimes there is no other option.

When you perform an “order by” this field,you can get something like this:

1 1
2 10
3 11
4 111
5 12
6 2
7 20
8 3

try the below query

select field from table order by field+0 asc

Post a Comment

Post a Comment (0)

Previous Post Next Post