php - SQL JOIN - two teams, one logo database -
i have 2 databases, 1 database(games) contains hometeamid , visitorid. , other database(teams) contains logonames , teamid. (games) hometeamid , visitorid related (teams) teamid.
i wanting run sql query outputs teams (games) database shows logos each respective team. want output this.
<item> <hometeamid> <home_logo> <visitid> <visitor_logo> </item>
when attempting query using php, use
select * games left join teams on games.homeid = teams.teamid
i can first logo hometeam fine, when use ,
select * games left join teams on games.homeid = teams.teamid , games.vistorid = teams.teamid
i nothing.
i able query work, don't logos.
let's @ second statement:
select * games left join teams on games.homeid = teams.teamid , games.vistorid = teams.teamid
you correctly joining 2 tables information need. however, , statement cause homeid = teamid , teamid = visitorid. therefore, can rewrite homeid = teamid = visitorid. never happen because homeid , visitorid never same given entry.
in order 2 sets of logos need 2 joins in order add columns. so, like:
select games.homeid, hometeam.logo homelogo, games.visitorid, visitorteam.logo visitorlogo games left join teams hometeam on games.homeid = hometeam.teamid left join teams visitorteam on games.visitorid = visitorteam.teamid;
Comments
Post a Comment