Order by Points but if the same order by in MySQL
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
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.
The correct answer is: Thanks!
ORDER BY Points DESC, Goal Difference DESC
This works for me
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:
This link its from an older version but it haven't changed for the other versions.