I looking for some tweak in mysql ordering , I normally select record from table and then order the record by Name(varchar) ASC but the number is always come first
here some example of my question (note. mysql sort the record with 0-9 first)
SELECT name FROM list ORDER BY name ASC
record returned:
1 star
2 star
9 slice
Ape
Age
Beg
Bell
Fish
Zoo
What i want is the alphabet order come first then follow by number
Desired output
Ape
Age
Beg
Bell
Fish
Zoo
1 star
2 star
9 slice
Use the following ORDER BY
clause:
ORDER BY IF(name RLIKE '^[a-z]', 1, 2), name
Ref this
SELECT name FROM list ORDER BY name * 1 ASC
Edited
SELECT name FROM list ORDER BY name * 1, name ASC
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With