Mateobus Posted March 11, 2007 Share Posted March 11, 2007 Hello, I am trying to run kind of a tough query for me. Here is how my tables are set up: I have a table called games with an id, and then homeid, and awayid for the two teams. Then I have a table called team, with a column called teamid and name. I would like to run a query that returns the game id, home team name, and away team name of all the games for a given team with id=x. Any help is greatly appreciated thanks in advance. Link to comment https://forums.phpfreaks.com/topic/42255-solved-a-tough-query-for-me/ Share on other sites More sharing options...
artacus Posted March 11, 2007 Share Posted March 11, 2007 SELECT g.id, away.name as 'away_team', home.name as 'home_team', DATE_FORMAT(g.game_date, '%m/%d/%y %l:%i %p') AS game_date, g.away_score, g.home_score FROM games AS g JOIN team AS home ON g.home_team_id = home.id JOIN team AS away ON g.away_team_id = away.id WHERE g.game_date < NOW() AND (g.home_team_id = 101 OR g.away_team_id = 101) Link to comment https://forums.phpfreaks.com/topic/42255-solved-a-tough-query-for-me/#findComment-205075 Share on other sites More sharing options...
Mateobus Posted March 12, 2007 Author Share Posted March 12, 2007 I really appreciate your help, thanks a lot. Link to comment https://forums.phpfreaks.com/topic/42255-solved-a-tough-query-for-me/#findComment-205235 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.