947740 Posted January 26, 2009 Share Posted January 26, 2009 I have a table with numerous numbers in it, and I try to sort it so that the largest numbers are at the top, and the lowest at the bottom. However, it sorts it like this: 99 983 95 95 95 94 934 93 91 9 9 Instead of going from largest to smallest. This is the mysql I have right now: select IP,total from visitor_data_ip order by TOTAL desc What mysql would do what I want? Thanks a lot. Quote Link to comment https://forums.phpfreaks.com/topic/142480-solved-sort-working-incorrectly/ Share on other sites More sharing options...
rhodesa Posted January 26, 2009 Share Posted January 26, 2009 what datatype is TOTAL? because you probably have it as a string type (like VARCHAR) and it should be a numeric type (like INT). you can cast it as an integer when sorting, but it's better to change it to the proper data type Quote Link to comment https://forums.phpfreaks.com/topic/142480-solved-sort-working-incorrectly/#findComment-746551 Share on other sites More sharing options...
fenway Posted January 27, 2009 Share Posted January 27, 2009 Definitely not a numeric column type, that's for certain. Quote Link to comment https://forums.phpfreaks.com/topic/142480-solved-sort-working-incorrectly/#findComment-747548 Share on other sites More sharing options...
dreamwest Posted January 27, 2009 Share Posted January 27, 2009 Make the column BIGINT with a value of 10 Quote Link to comment https://forums.phpfreaks.com/topic/142480-solved-sort-working-incorrectly/#findComment-747556 Share on other sites More sharing options...
947740 Posted January 27, 2009 Author Share Posted January 27, 2009 what datatype is TOTAL? because you probably have it as a string type (like VARCHAR) and it should be a numeric type (like INT). you can cast it as an integer when sorting, but it's better to change it to the proper data type Definitely not a numeric column type, that's for certain. I have no idea what I was thinking when I made it varchar...now it works. Thanks a lot. Make the column BIGINT with a value of 10 I just made it int(30), because that is as big as it will be. Thanks, though. Quote Link to comment https://forums.phpfreaks.com/topic/142480-solved-sort-working-incorrectly/#findComment-747558 Share on other sites More sharing options...
fenway Posted January 27, 2009 Share Posted January 27, 2009 Make the column BIGINT with a value of 10 This doesn't do anything to the actual column type -- you know that, right? Quote Link to comment https://forums.phpfreaks.com/topic/142480-solved-sort-working-incorrectly/#findComment-747560 Share on other sites More sharing options...
dreamwest Posted January 27, 2009 Share Posted January 27, 2009 This doesn't do anything to the actual column type -- you know that, right? Now i do.. All my integer columns are made with INT and ive had no probs with sorting Quote Link to comment https://forums.phpfreaks.com/topic/142480-solved-sort-working-incorrectly/#findComment-747565 Share on other sites More sharing options...
corbin Posted January 27, 2009 Share Posted January 27, 2009 I just made it int(30), because that is as big as it will be. Thanks, though. The most digits (in base 10 representation) that an integer will ever have is 10. Just to clarify, in case googling didn't tell you, dreamwest, the length is really quite pointless unless you're doing zerofill. A bigint is still x bits and an int is still y bits, no matter what length you tell it. Quote Link to comment https://forums.phpfreaks.com/topic/142480-solved-sort-working-incorrectly/#findComment-747739 Share on other sites More sharing options...
947740 Posted January 28, 2009 Author Share Posted January 28, 2009 The most digits (in base 10 representation) that an integer will ever have is 10. Just to clarify, in case googling didn't tell you, dreamwest, the length is really quite pointless unless you're doing zerofill. A bigint is still x bits and an int is still y bits, no matter what length you tell it. Ah. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/142480-solved-sort-working-incorrectly/#findComment-748468 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.