SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    a join with two keys relating to same table

    Hi,
    I have a table TEAMS and a table FIXTURES. I'd like to display a list of fixtures (xxx vs. yyyy) but can't work out how to reference the two teams. Can anyone help?

    at the moment I am using two parallel queries
    SELECT * FROM FIXTURES, TEAMS WHERE
    TEAMS.teamId = FIXTURES.challengingTeamId
    and
    SELECT * FROM FIXTURES, TEAMS WHERE
    TEAMS.teamId = FIXTURES.challengedTeamId
    but wondered if I could get it in one query?

    thanks, Peter

  2. #2
    Tranceoholic lilleman's Avatar
    Join Date
    Feb 2004
    Location
    Írebro, Sweden
    Posts
    2,716
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    I think that something like the query below should give you the desired result.

    Code:
    SELECT ta.teamId, tb.teamId FROM fixtures AS f
      INNER JOIN teams AS ta ON ta.teamId = f.challengingTeamId
      INNER JOIN teams AS tb ON tb.teamId = f.challengedTeamId
    Yours, Erik.
    ERIK RIKLUND :: Yes, I've been gone quite a while.

  3. #3
    SitePoint Evangelist
    Join Date
    Jul 2000
    Location
    Warwickshire, England
    Posts
    557
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks that was just what I was looking for


Bookmarks

Posting Permissions

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