1

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

1 Answer 1

4

You just need to specify two conditions (separated by commas) in your ORDER BY clause:

ORDER BY ranking, id
Sign up to request clarification or add additional context in comments.

3 Comments

I have tried that, but it is not giving me the correct entry from the database.
@user981053 then you need to give us more information - edit the question with an example of the data and what you want.
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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.