Liam
Liam

Reputation: 65

Order by different column if results are the same

Basically, if two people have the same score in my game, the person who is in the first position on the leaderboard is whichever score / record is the newest.

How can I change my query so that if two or more people have the same score, it then sorts by name alphabetically and puts that score on the top. My query is:

$result = mysql_query("SELECT * FROM test ORDER BY Score DESC");

Upvotes: 0

Views: 25

Answers (1)

Joachim Isaksson
Joachim Isaksson

Reputation: 181037

Just order by both in preference order;

SELECT * FROM test ORDER BY Score DESC, Name ASC

Upvotes: 2

Related Questions