   [web] SQL for Round Robin
  Let me start off by saying that my SQL knowledge is rather limited. I've just finished building the site and database for a friends league, but he wants it to do more (typical).Each player in the league has to face each other player twice, with 3 points for a win, 1 for a draw, and none for a loss. There's also a tie-breaker worked out.The problem is, the current database only keeps track of results, but not who those results were against, which is problematic, as some people are having to drop from the league, and we want to remove all points their opponents received from their games.Can someone explain how best to go about this in MySQL? The only idea I had was making tables for each player, but I don't want to start making tables left, right and centre if there's a better way of doing this.Any help would be much appreciated.   
  You should create a table, possibly named score, with two keys (each one of these is an id to a player). You should also probably make sure that key1's value is always smaller than key2's value so that you can directly see if two players have had a match. (Enforces uniqueness).If a player has to be deleted, you have to remove all score instances (or disable them for the sake of keeping history) that have either one of the two keys equal to the player's key.   ;  What arithma said. In case the number of players per match can vary, you could add an extra table linking a player to a match:table player- id- nametable match- id- date- winner (optional, a player id)table match_player- match (a match id)- player (a player id)- score;  I don't understand the keys part I'm afraid, in particular about the first key being shorter than the second. How does that enforce uniqueness? Especially when each player faces off twice. Unfortunately it seems I'm missing something with that. Could you possibly explain that a bit more fully?   ;  If you had the key constraint, you can always make sure if two players have played a match by querying for their keys in an ordered manner. (Check if player with lower key had a match versus player with higher key..) It's not necessary and you can replace this by an or condition (check if player played against the other player in two ways)   ;Quote:Original post by webwraithI don't understand the keys part I'm afraid, in particular about the first key being shorter than the second. How does that enforce uniqueness? Especially when each player faces off twice. Unfortunately it seems I'm missing something with that. Could you possibly explain that a bit more fully?He's saying that you need make sure that the system doesn't recognize A-B as being a different combination than B-A. If you sort the two items before writing to the table, it takes care of that situation, because you will never get a B-A situation.