Reputation: 2846
I have been using MySQL for a long time and I have never run across this issue. I have a table that stores the scores for an application. For some reason, when I sort by score ASC
, the highest score is shown first with the lowest score being last. Please see the screenshot below:
Here is my query:
SELECT category, subject, max(score) as score FROM scores
WHERE customer_id = 1086 AND category = 'Business'
GROUP BY subject ORDER BY score ASC
Any thoughts on why this is happening?
Upvotes: 1
Views: 1671
Reputation: 3137
Try selecting CAST(max(score) AS INTEGER) as Score
and then ORDER BY Score
.
Upvotes: 0
Reputation: 11832
Change the datatype of score from string (eg varchar/text) to a number (eg int). That should solve the sorting issue.
When the values are sorted on string basis (alphabetically), the '6' in '60' comes before '8'.
As a temporary work-around you can also try order by score+0 asc
to try and convert your value into a number.
Upvotes: 4