Reputation: 3
I tried to order by Integer but it seemed that it order by the larger to the smaller number but it order by 2-digit then 3-digit
sc is the score i need to order
Code i used
SELECT * FROM `users` ORDER BY `sc` DESC
The result are :
47
3
102
Upvotes: 0
Views: 67
Reputation: 69440
Looks like datetype of sc
is char/varchar. You have to cast it to an integer:
SELECT * FROM `users` ORDER BY cast(`sc` as UNSIGNED) DESC
Upvotes: 3
Reputation: 44844
You may use silent conversion to integer as
select * from users order by sc+0 desc
Upvotes: 0
Reputation: 389
Your query should be like this:
SELECT * FROM `users` ORDER BY CAST(`sc` AS SIGNED INTEGER) DESC
Upvotes: 1