Table with its own id
, two foreign keys - player1_id
, player2_id
, and two columns for wins wins_player1
, wins_player2
.
--------------------------------
| id | p1_id | p2_id | w1 | w2 |
--------------------------------
| 1 | 1 | 2 | 2 | 0 |
--------------------------------
| 2 | 1 | 3 | 1 | 1 |
--------------------------------
| ...| | | | |
--------------------------------
This way, when two players play a game you don't insert a new tuple to the table, you just update their scores.
For an example, if players 1 and 2 played, and the player 1 won you would do:
UPDATE scores WHERE p1_id = 1 AND p2_id = 2 SET w1 = w1 + 1;