Two teams, same points: every league breaks the tie differently
Two clubs finish level on points. Which one goes above the other? Most developers answer "goal difference" and move on. That answer is right in England and wrong in Spain, and if you are sorting a table in your own code you have probably shipped the bug already.
The rules are not universal
Every league starts with points. After that they diverge, and the divergence is not cosmetic. A club can sit above another it trails on goal difference, because it beat that club twice.
These are the orders we apply, taken from each competition's own regulations:
| Competition | After points, in order |
|---|---|
| Premier League | Goal difference, goals scored |
| Ligue 1 | Goal difference, goals scored |
| LaLiga | Head-to-head points, head-to-head goal difference, goal difference, goals scored |
| Serie A | Head-to-head points, head-to-head goal difference, goal difference, goals scored |
| Primeira Liga | Head-to-head points, head-to-head goal difference, goal difference, wins, goals scored |
| Süper Lig | Head-to-head points, head-to-head goal difference, goal difference, goals scored |
| Bundesliga | Goal difference, goals scored, head-to-head points, head-to-head goals, away goals |
| Eredivisie | Goal difference, goals scored, head-to-head points, head-to-head goal difference, head-to-head away goals |
| EFL Championship | Goal difference, goals scored, head-to-head points, wins, away goals |
| Champions League | Goal difference, goals scored, away goals, wins, away wins |
| Europa League | Goal difference, goals scored, away goals, wins, away wins |
| Conference League | Goal difference, goals scored, away goals, wins, away wins |
Four of the twelve put head-to-head first. Three more use it, but only after goal difference has failed to separate anybody. Three cannot use it at all, for a reason worth understanding.
Why the European competitions are different
Each UEFA league phase is a single table of 36 clubs, and they do not all play each other. There is no head-to-head record between two clubs that never met, so the criterion is not merely unused, it is undefined. UEFA goes to goal difference, then goals scored, then away goals, which is why all three of its competitions share one row of this table.
The part that catches people out
A head-to-head criterion cannot be applied until every tied club has played every other tied club the full number of times. In a league where clubs meet twice, that means both fixtures have to be done.
So in October, LaLiga's head-to-head rule is dormant. Two clubs level on points are separated by goal difference, exactly as in the Premier League. The rule wakes up later in the season, and the table can reorder without a ball being kicked by the clubs involved.
If you compare a mid-season LaLiga table against your own sort and they agree, that does not mean your sort is right. It means the rule has not started yet.
What to do about it
Do not re-sort the table client-side. Every standings response already carries the position, and that position was computed with the competition's own rules:
curl -H "X-RapidAPI-Key: YOUR_KEY" \
-H "X-RapidAPI-Host: la-liga2.p.rapidapi.com" \
"https://la-liga2.p.rapidapi.com/standings"
{
"data": [
{ "position": 1, "team": { "name": "Real Madrid" }, "points": 21, "goalDiff": 12 },
{ "position": 2, "team": { "name": "Barcelona" }, "points": 21, "goalDiff": 14 }
]
}
That ordering is not a mistake to correct. Barcelona are second on a better goal difference
because Madrid took more points from the two meetings, and in Spain that comes first. Sorting this
array by goalDiff would produce a table that disagrees with the league.
Render in the order you receive. If you need to sort for another reason, sort by
position.
If you are building your own table anyway
Some people need to, for a projection or a what-if. Two things will bite you.
First, the mini-table. Head-to-head points are computed only among the tied clubs, using only the matches between them. Three clubs tied on 40 points produce a three-team table from their six meetings, and that table decides the order.
Second, the criteria are applied one at a time until one of them separates the clubs, and it is applied to the whole tied group rather than pairwise. A pairwise comparison sort is not the same thing and will produce a different answer when three or more clubs are level.
Both are the reason we compute it once, on the server, per competition.