I need an SQL query that orders a column by a ranking system, but if the ranks are the same, use the id as only a secondary, last resort order. Can anyone help me accomplish this? I have the system working with ORDER BY, but if rankings are the same, it screws up the system. I only need the primary, secondary ORDER BY code and not a whole query.
1 Answer
You just need to specify two conditions (separated by commas) in your ORDER BY clause:
ORDER BY ranking, id
3 Comments
user981053
I have tried that, but it is not giving me the correct entry from the database.
John Carter
@user981053 then you need to give us more information - edit the question with an example of the data and what you want.
user981053
I figured it out. I was using (ORDER BY rank, id DESC) instead of using (ORDER BY rank DESC, id DESC). Thank you for the help.