Question

I now have my table results ordered by points. But it needs to be order by points but if this is the same than order by Difference.

Now is have is this:

... ORDER BY Points DESC";

But i want to have something like this:

... ORDER BY Points (if two have the same amount) Than ORDER BY Goal Difference

Hope you can help

Was it helpful?

Solution 2

The correct answer is: Thanks!

ORDER BY Points DESC, Goal Difference DESC

This works for me

OTHER TIPS

It would help if you included the full query in your question. The order by clause can accept multiple arguments. As you phrase the question, the answer would be something like:

order by Points desc, GoalDifference

You might want an expression:

order by Points, t1.Goals - t2.Goals

These are also allowed in the order by.

When you order by two columns it takes the first column and for equal values of the first column it will order by the second one, so it just do what you need here.

You can use: order by Points, GoalDifference

or you can even do it in diferent orders:

order by Points DESC, GoalDifference

order by Points, GoalDifference DESC

You can always refer to the MYSQL Documentation:

https://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html

This link its from an older version but it haven't changed for the other versions.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top