Natural sort for MySQL

Given the list:

1
2
3
10
11
12a
12b
12c
Alpha
Beta
Charlie

If running a normal ORDER BY it will order the list:
1
10
11
12a
12b
12c
2
3
Alpha
Beta
Charlie

You can CAST the results to UNSIGNED during the ORDER BY to achieve naturally sorted results as shown in the first list.

Leave a Reply

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