The task is to sort the data from the table in alphabetical order by the title field, the stored data can be Russian or English alphabet and begin with a digit.

Here is a simple request that I wrote

 SELECT title FROM films ORDER BY `title` 

As you can see, by default, the database returns data that starts with a number, but I need to first have data starting with letters.

Help or tell me how to bring this request to mind.

 "2001: A Space Odyssey" "2001: A Space Odyssey" "2001: A Space Odyssey" "2001: A Space Odyssey" "Breaking Bad" "Butch Cassidy and the Sundance Kid" "Butch Cassidy and the Sundance Kid" "Butch Cassidy and the Sundance Kid" "Butch Cassidy and the Sundance Kid" "Casablanca" "Casablanca" "Casablanca" "Casablanca" "Charade" "Charade" "Charade" "Charade" "Cool Hand Luke" "Cool Hand Luke" "Cool Hand Luke" "Cool Hand Luke" "dfg" "dfgdg" "dfsgreg" "Get Shorty " "Get Shorty " "Get Shorty " "Get Shorty " 

I am also considering the option of sorting this data array with php tools, but I want to know whether it is possible to solve this problem solely using SQL.

  • one
    replace in order by all the numbers on the curly bracket '{', for example. How to do this depends on the sql dialect used. most likely than something like replace, although it will be cumbersome. Provided that your sql sorts in ascii character codes and the '{' it comes after the letters - Mike
  • one
    For MySQL, for example, just ORDER BY 0+title, title . For other DBMS different. Specify the exact dialect. - Akina
  • Thank you, everything turned out to be much easier than I thought. - Gildars

0