0
Name      Rank    XP
-----------------------
Craig     0       100
Morris    1       0
Roger     0       4000

I want my SQL statement to pull names from the above table in the order that the RANK field takes priority, followed by the XP field.

So the correct order would be;

Morris
Roger
Craig

I've tried a 'ORDER BY Rank ASC, XP DESC' but can't seem to get it to work.

Any tips?

4
  • what do you mean, "but can't seem to get it to work" ? Show the query and the error message you are getting, please. Commented Dec 11, 2013 at 20:52
  • 5
    sounds like you need Rank desc? Commented Dec 11, 2013 at 20:52
  • Maybe you need ORDER BY Rank DESC, XP DESC? I agree that we need to see entire query and output. Commented Dec 11, 2013 at 20:54
  • My bad, how stupid of me :/ thanks Commented Dec 11, 2013 at 20:54

2 Answers 2

3
ORDER BY [Rank] DESC, XP DESC

will produce

Morris
Roger
Craig


ORDER BY [Rank] ASC, XP DESC

will produce

Roger
Craig
Morris
Sign up to request clarification or add additional context in comments.

1 Comment

I think the key distinction is that he should be ordering by rank descending instead of ascending.
0

"RANK" is an SQL reserved word. Try this:

ORDER BY [RANK] DESC, XP DESC

Comments

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.