sql order by from highest to lowest value

55,221

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.

Share:
55,221
ntm
Author by

ntm

Updated on February 03, 2020

Comments

  • ntm
    ntm over 4 years
    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.

  • Dismissile
    Dismissile over 10 years
    ASC = Ascending, DESC = Descending in case OP didn't realize this.