Sort the mysql alphanumeric value

I want to find the maximum value in a column.

Column values: E00004, A00005, B00011, H-00001, E2100112, EFQ20098, ESSF20003

I just want to sort the values ​​by their number. Ignore the alphabets. It should be like this: I am using MYSQL

E2100112, ESSF20003, EFQ20098, B00011, A00005, E00004, H-00001

+5
source share
1 answer

Assuming the last 5 digits is a number:

select columnName from tableName
order by convert(int, right(columnName, 5)) desc

As pointed out by @IkeWalker, a number can be of arbitrary size. To do this, you need to use the while loop to check the number.

Or you may have a feature for you!

Check out this article!

+3
source

All Articles