Brian Brian - 8 days ago 6
SQL Question

SQL Simple ORDER BY

I'm new to SQL and I don't think this question should be hard to answer. I have a high-score table for a game that contains the columns name, score, and rank. I want to know how I can order the table by descending order each time a new score is added so the table can always stay ordered by score.

I know this is the wrong way of doing this, but I hope this makes my point kind of clearer.

UPDATE `HSTable`.`Highscores` ORDER BY `Highscores`.`score` DESC;


What is the correct way of approaching this?

One more thing, is there a way I can set it so that the ranking value always stays where it's suppose to be from the SQL, for example, 1st place is always at the top regardless the score?

Answer

generally we use order by while fetching data from table

so we use

SELECT * FROM `HSTable` ORDER BY `score` DESC