Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 943
ntm Avatar asked Dec 01 '22 20:12

ntm


1 Answers

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.

like image 108
Paul92 Avatar answered Dec 03 '22 08:12

Paul92