Sorting a MySQL string column as a number

Posted on 01-07-2017 by Nadir Latif


Source: https://stackoverflow.com/questions/44829035/wordpress-sort-posts-containing-numbers-and-letters-alphabetically/44857800#44857800

To sort a MySQL string column containing a number we can use the SUBSTRING and CAST functions. The SUBSTRING function should extract the numbers inside the string. The CAST function will convert the extracted string to a number.