1

I'm creating a database that is going to be used for a sporting competition. To view the results of a game, I need to join six tables together:

  • Season s
  • Round r
  • Rounddetails rd
  • Match m
  • Matchdetails md
  • Game g

I want the select statement to return something like this:

g.gameid, g.pointsfor, g.pointsagainst, md.matchdetailsid, m.matchid, rd.rounddetailsid, r.roundid, s.seasonid

Could anyone help me write a MySQL statement that will return that?

Please click the link to view the tables

a tables

EDIT: so far I have tried this query:

select
`s`.`seasonID` AS `seasonID`,
`r`.`roundID` AS `roundid`,
`rd`.`roundDetailsID` AS `roundDetailsID`,
`m`.`matchid` AS `matchid`,
`md`.`matchDetailsID` AS `matchDetailsID`,
`g`.`gameid` AS `gameid`,
`g`.`pointsfor` AS `pointsfor`,
`g`.`pointsagainst` AS `pointsagainst`
from (((((`season` `s` left join `round` `r` on((`s`.`SeasonID` = `r`.`SeasonID`)))
left join `rounddetails` `rd` on((`r`.`RoundID` = `rd`.`RoundID`)))
left join `match` `m` on((`rd`.`matchid` = `m`.`matchid`)))
left join `matchdetails` `md` on((`m`.`matchid` = `md`.`matchid`)))
left join `game` `g` on((`md`.`matchdetailsid` = `g`.`matchdetailsid`)))
4

1 回答 1

0
SELECT DISTINCT g.gameid, g.pointsfor, g.pointsagainst, md.matchdetailsid, m.matchid, rd.rounddetailsid, r.roundid, s.seasonid
FROM Match AS m
INNER JOIN MatchDetails as md
ON Match.MatchId = MatchDetails.MatchId
INNER JOIN Game as g
ON MatchDetails.MatchDetailSid = MatchDetailSid
INNER JOIN RoundDetails as rd
ON Match.MatchId = RoundDetails.MatchId
INNER JOIN Round as r
ON Round.RoundId = RoundDetails.RoundId
INNER JOIN Season as s
ON Round.SeasonId = Season.SeasonId
WHERE MatchId = 1
于 2012-12-06T20:55:23.870 回答