I am using a Query which sorts like;
1
2
3A
3
4A
4
But I want to get it
1
2
3
3A
4
4A
What I am using is
SELECT * FROM `sections` ORDER BY CAST(`act` as DECIMAL) ASC
What I exactly want is First Number then Alphanumeric
3 then 3A
Considering that you'll always have integer first and then characters in your acts column. Normally this is called Natural Sorting.
Problem Understanding:
1, 1A, 1B, 1AB...1, 10, 100....We can sort in following manner.
SELECT * FROM sections
ORDER BY CAST(acts AS UNSIGNED), acts
Check corresponding fiddle. It is working for MySQL 5.5, 5.6, 5.7 & 8.0.
natsort()to achieve that.actanyway? normal order by works fine sqlfiddle.com/#!9/50fb55/1varcharforactbecause some time it has only numeric and some time alphanumeric