ntm
ntm

Reputation: 741

sql order by from highest to lowest value

SELECT * FROM highscore ORDER BY score

This code always sorts my values for lowest to highest but I want them from the highest to the lowest.

Actually I have two sets of data in my table and I always get:

0
235235

But I need it to be like this:

235235
0

I have already tried:

SELECT * FROM highscore ORDER BY CAST(score AS int)

But that gave me a syntax-error:

"You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INT)' at line 1"

In my table score is set as int(100).

Does anybody have a solution how I could sort them like that? There will never be negative or non-int values.

Upvotes: 4

Views: 64362

Answers (1)

Paul92
Paul92

Reputation: 9062

You have to use

SELECT * FROM highscore ORDER BY score DESC

There also exists

SELECT * FROM highscore ORDER BY score ASC

, but this is the default behaviour.

Upvotes: 19

Related Questions