MySQL order by string with numbers

后端 未结 7 876
谎友^
谎友^ 2020-12-11 01:57

I have strings such as M1 M3 M4 M14 M30 M40 etc (really any int 2-3 digits after a letter) When I do \" ORDER BY name \" this returns:

M1, M14, M3

7条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-11 02:31

    Another method i used in my project is:

    SELECT * FROM table_name ORDER BY LENGTH(col_name) DESC, col_name DESC LIMIT 1 
    

提交回复
热议问题