I want to sort a field alphanumerically in the database. It turns out to be trickier than I thought. This is just example values, the content can vary, but I hope it's enough to get the idea.
I want to sort this list:
11
01
1
1A
01B
20a
01a
20
1b
2b
02a
Like this:
1
01
1A
01a
1b
01B
02a
2b
11
20
20a
Note that the relative ordering of equivalent numbers with and without leading zeroes is not important, it can be 1 01
or 01 1
.
I've tried CAST(field AS UNSIGNED)
but it doesn't work. Ideas?