Jump to content

[SOLVED] Sort Working Incorrectly


947740

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.