Results 1 to 3 of 3

Thread: Query Help

  1. #1
    Join Date
    Oct 2004
    Location
    Toronto
    Posts
    3

    Unanswered: Query Help

    Hi

    I'm trying to get a query working.

    My db structure is

    Schedule
    id | home | away | home_score | away_score

    where 'home' and 'away' reference primary keys in the Team table

    Team
    id | name | city

    What I would like to do, is for each game in Schedule, select the actual name's of the teams playing (instead of just there ids)
    I can't figure out the JOIN involved in this.

    Any help would be appretiated, thanks
    Last edited by rprp; 11-08-04 at 11:59.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    select t1.name as "home team", t2.name as "away team", s.home_score, s.away_score
    from schedule s, team t1, team t2
    where s.home=t1.id and s.away=t2.id;

  3. #3
    Join Date
    Oct 2004
    Location
    Toronto
    Posts
    3
    Thank you very much!

    I had something similiar, but rather than "Team t1, Team t2" I was only selecting Team once. Argh, should have realized that.

    Thanks again.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •