Mutley Posted October 8, 2006 Share Posted October 8, 2006 I have a list of numbers and when I order them DESC, it works fine through from 1 to 9 (9 at top, 1 at bottom) but 10, 11, 12 etc is acting like 1 and goes to the bottom to.How do I correct this? Quote Link to comment Share on other sites More sharing options...
john_6767 Posted October 8, 2006 Share Posted October 8, 2006 u can put 0 in front of the numbers smaller than 10.. Quote Link to comment Share on other sites More sharing options...
trq Posted October 8, 2006 Share Posted October 8, 2006 What field types are you using? Quote Link to comment Share on other sites More sharing options...
paul2463 Posted October 8, 2006 Share Posted October 8, 2006 If you have numbers written in text or characters, and you want to sort them in Ascending order and you don't want this:mysql> select number from (table) order by number;+--------+| number |+--------+| 1 || 10 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 |+--------+Use this:mysql> select number from (table) order by (number+0);+--------+| number |+--------+| 1 || 2 || 3 || 4 || 5 || 6 || 7 || 8 || 9 || 10 |+--------+The (field + 0 ) converts the text/character in the field into an integer.Alternativley remap your table so that the column containing the numbers is type "integer" Quote Link to comment Share on other sites More sharing options...
fenway Posted October 9, 2006 Share Posted October 9, 2006 Yes, the +0 will cast your character representations as number on-the-fly, but you should definitely change the colun type. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.