I have a table which has three fields: "Id, Name, Sequence".
In the "Sequence" column there are the following entries: 1, 2, 3, 4, 2a, 5, 2b, 2c, 3, 4a (Row wise).
Now I want to a mysql query which can sort these values like:
1, 2, 2a, 2b, 2c, 3, 4, 4a, 5.
I have tried following query
SELECT * FROM table_name ORDER BY CAST(sequence AS UNSIGNED) ASC.
But it's not working.
SELECT * FROM table_name ORDER BY sequence asc10before2since the field isvarcharnot numeric.cast(sequence as unsigned)by itself doesn't work, either. It doesn't subsort2,2a,2bfor example. If your list has2b,2,2a, then it leaves that order.3bcomes before3, but it shouldn't.