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
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)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.