sql - Tournaments, Players and Match Relations -


i have multiple players in multiple tournaments in multiple seasons (tables: player, tournament, season). match between 2 players has reference specific tournament , specific season.

table match     id     season_id     tournament_id     player_home     player_away

let's natural assign players tournaments obvious benefits. one-to-many table between seasons , tournaments (call table competition) , many-to-many table competitions , players?

table competition     id     season_id     tournament_id  table competition_player     id     competition_id     player_id  table match     id     competition_id     player_home     player_away

or there more simple/better way achieve this?

thanks advice.

sqlfiddle

very basic still can see relationship. here.

structure

tables

  • players

    -------------------------- |id | name | otherinfo   | -------------------------- | 1 | john | player info | -------------------------- | 2 |  tom | player info | -------------------------- 
  • seasons

    ----------------------------------- |id | seasonname    | seasoninfo  | ----------------------------------- |01 | myfirstseason | season info | ----------------------------------- 
  • tournements

    ------------------------------------ | id | seasonid | tournamentname   | ------------------------------------ |001 |    01    | myfirsttournament| ------------------------------------ 
  • encounters

    --------------------------------------- | id | firstplayerid | secondplayerid | --------------------------------------- |  |       1       |       2        |   --------------------------------------- 
  • matchs

    ----------------------------------------------- | id | tournamentid | encounterid | matchinfo | ----------------------------------------------- |0001|     001      |           | info | ----------------------------------------------- 

thing you're using many keys nothing. need take step think design. know took out columns it's example's sake. i'm sure understand put them back. wanted show relationships between tables.

query

let's imply want basic information (once again example)

select m.id,  t.tournamentname, s.seasonname,  (select pl.name players pl   join encounters en on pl.id = en.firstplayerid   pl.id = en.firstplayerid) [firstplayername], (select pl.name players pl   join encounters en on pl.id = en.secondplayerid  pl.id = en.secondplayerid) [secondplayername], m.matchinfo  matchs m  join tournaments t on m.tournamentid = t.id join encounters e on m.encounterid = e.id join seasons s on  t.seasonid = s.id 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -