Jump to content

[SOLVED] A tough query... for me


Mateobus

Recommended Posts

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

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)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.