Below are the contents of sid column in a table ( where “S05201215” is
a fixed string and remaining part of the Sring is a sequence of
numbers)
S052012151
S052012152
S052012153
S052012154
S052012155
S052012156
I want to sort the the remaining part of the string (i.e.
the numbers that i’ve appended to the string S05201215 in
descending order .. what modifications should i do to the below query
to get desired output?
SELECT `sid` FROM `mytable` order by SUBSTRING(`sid`,10,length(`sid`))
To sort in descending order, just add “DESC” to the end of your ORDER BY:
However, if the values of sid are of different lengths, you are probably going to want to cast the values to a numeric type before sorting: