Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MySQL Query ORDER BY certain values before others

I am developing a game highscore where the time of completion is stored in a database, but if you don't complete the level but save your highscore, the completion time is 0.

I am trying to make a query which lists the highscore with the lowest completion time first, but my simple ORDER BY is sticking all of the 0 completion times at the start of course!

Is there any way I can order it like this, but have the 0's at the bottom.

I have tried:

SELECT FROM highscores ORDER BY completiontime > 0, completiontime = 0 ASC

Anyone have any ideas?

like image 893
Jamie Avatar asked Feb 26 '23 15:02

Jamie


1 Answers

SELECT *
FROM highscores
ORDER BY completiontime = 0, completiontime
like image 124
Mark Byers Avatar answered Mar 06 '23 18:03

Mark Byers