ThinkNewDev
ThinkNewDev

Reputation: 668

Order By problem with int Mysql

I have prices in a database as INT if I order by I get

97,650

ends of appearing before

975,455

after sorting in DESC

It appears that since the 6 in the first price is greater than the 3rd place position in the second price, it counts that as a larger number.

Has anyone run into this problem and know how to solve it?

Upvotes: 0

Views: 3163

Answers (2)

superUntitled
superUntitled

Reputation: 22527

To test, try this slow and sad query.

select prices from (table) order by (prices+0);

If that query works, then it is likely your column is not an INT column. The (prices+0) makes certain that the data is treated as an integer.

Once you have found that this does indeed work for you, you need to alter the column to be an INT column.

Upvotes: 1

Your Common Sense
Your Common Sense

Reputation: 157863

You should change the field type from varchar to int.

Upvotes: 0

Related Questions