1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

SQL Inner Join

Discussion in 'SQL Server' started by coolcalimba, Sep 19, 2007.

  1. coolcalimba

    coolcalimba New Member

    Joined:
    Sep 19, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Hello

    I have the tables set up as below (simplified)

    BET (BetID, Title, Date, Event, Bookie1, Bookie2)

    BOOKIE (BookieName, URL)

    Every bet contains (among others) 2 bookies.
    Each bookie has an URL.

    For every bet I need a command to select all from bet along with the URL of both the bookies that are involved. This is the closest I have got but there is "incorrect sytax near c".

    SELECT a.*, b.url as 'url1', d.url as 'url2'
    FROM (BookieBet a INNER JOIN Bookies b on a.Bookie1 = b.BookieName) c INNER JOIN Bookie d on c.Bookie2 = d.BookieName

    Any help appreciated.
    Cheers
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    You are not specifying the table name near C Also I am just giving a try and its not a tested one.

    Code:
    Select b.*, b1.url, b2.url from BET b, BOOKIE b1, BOOKIE b2
    where b1.BookieName = b.Bookie1 AND b2.BookieName = b.Bookie2
    
     
  3. coolcalimba

    coolcalimba New Member

    Joined:
    Sep 19, 2007
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0
    Cheers mate, seems I was over complicating things slightly.!
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,283
    Likes Received:
    364
    Trophy Points:
    83
    Did that SQL work
     

Share This Page