I do not know, maybe a crazy question, but still. It is necessary to sort the data that is pulled out from the database by name in ascending order. File names are from 1.jpg to 2000.jpg . When sorting with the following query:

 SELECT * FROM `tbl` ORDER BY `name` ASC 

output data in the following:

1.jpg 10.jpg 100.jpg 1000.jpg 1001.jpg 1002.jpg 1003.jpg 1006.jpg и т.д.

Actually the question: how to sort this business, so that the output data was as follows:

1.jpg 2.jpg 3.jpg и т.д.

    2 answers 2

     SELECT * FROM `tbl` ORDER BY (`name`+0) ASC 
    • thanks, did not know about this opportunity - Elime
     SELECT * FROM `tbl` ORDER BY name+0 ASC 

    Thus, it will be sorted as a number.

    • accordion :)))) - Alex Kapustin
    • one
      when I answered - there was no answer yet, it appeared later, something was going on from ajax site - Maksym Prus
    • Read smilies;) Plus to not be offended :) - Alex Kapustin
    • Alaverdi :) - Maksym Prus