In this tutorial, we will look at sorting string column containing numbers in SQL.
How to sort a string column containing numbers
If you have ever wondered how can you sort a column which contains a combination of string and number, please have a look at the following example.
If you want the display output to be as follows:
Then the following query can help you.
select name from mytable order by CAST(SUBSTRING(name,LOCATE(‘VIZVRM’,name)+6) AS SIGNED), SUBSTRING(name,-1);
name is the column name in the table that you want it to be displayed in the sorted order.
mytable is the table name.