Jump to content

[SOLVED] Can I get all this info in One query


jdubwelch

Recommended Posts

I have two tables: "bowl_games" and "teams"

 

table "bowl_games:

bowlgames.png

 

table "teams":

teams.png

 

I'm trying to select the following with only query if possible:

 

    bowl_games.bowl_game_id, bowl_games.name, bowl_games.date,

 

    AND

 

    teams.team_id, teams.name, teams.record, teams.rank  (from the home_id & away_id associated to the bowl_game_id)

 

 

This is the query I used, but as you can see I'm getting the bowl_game info twice.

 

SELECT bg.bowl_game_id, bg.name, bg.date, t.team_id, t.name 
FROM `bowl_games` AS `bg`, `teams` AS `t` 
WHERE bg.away_id = t.team_id OR bg.home_id = t.team_id

 

query.png

 

Is it possible?  What would you do?

 

Link to comment
Share on other sites

try this

select bg.bowl_game_id,bg.name,bg.date,t1.team_id as Away_Id,t1.name as Away_Name,t2.team_id as Home_Id,t2.Name as Home_name
from bowl_games bg
left outer join teams t1 on t1.team_id = bg.away_id
left outer join teams t2 on t2.team_id = bg.home_id

 

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.