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? Link to comment https://forums.phpfreaks.com/topic/23345-order-by-desc/ 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.. Link to comment https://forums.phpfreaks.com/topic/23345-order-by-desc/#findComment-105805 Share on other sites More sharing options...
trq Posted October 8, 2006 Share Posted October 8, 2006 What field types are you using? Link to comment https://forums.phpfreaks.com/topic/23345-order-by-desc/#findComment-105806 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" Link to comment https://forums.phpfreaks.com/topic/23345-order-by-desc/#findComment-105808 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. Link to comment https://forums.phpfreaks.com/topic/23345-order-by-desc/#findComment-106100 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.