1

I have a problem ordering mysql results in the right order. I have string values also containing numbers in some cases and i need them to be ordered the right way.

For example instead of:

file name aaa
Some file name 1
Some file name 10
Some file name 2
Some file name 20'

I need them to be ordered "human logicaly":

file name aaa
Some file name 1
Some file name 2
Some file name 10
Some file name 20'

... problem is, that Some file name is not some kind of prefix, so I can not use substring. Those string values can be different. Also those values cannot be numbered (added some ordering prefix).

Is there some simple solution? Thank you for any ideas.

double-beep
  • 5,031
  • 17
  • 33
  • 41
johny7cz
  • 43
  • 3
  • Here's a previous question that answers your question. http://stackoverflow.com/questions/11808573/sql-order-by-string-number – Mohamed Nuur Sep 25 '12 at 01:23
  • Hi, the basic idea is order by the non-numeric part first, then order by the numeric part of the expression. You can get numeric part by http://venerableagents.wordpress.com/2011/01/29/mysql-numeric-functions/ – Larry Sep 25 '12 at 01:25
  • Don't forget to do the sort _case-insensitive_, otherwise `file name aaa` will come *after* all the `Some file name...` entries. – Jim Garrison Sep 25 '12 at 03:01

0 Answers0