SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: SQL Query Help.

  1. #1
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SQL Query Help.

    Hey. I can't really figure out how to get this query to work. Any help would be greatly appreciated!

    Tables:

    covar
    ->tId1
    ->tId2
    ->covar

    asx200
    ->id
    ->tickerSymbol

    Where tId1 & tId2 correspond to ids in asx200.

    I want to write a select statement which returns the covar and the tickerSymbols which correspond to both tId1 and tId2. So for example:

    covar: 1, 2, .001

    asx200:
    1,BHP
    2,CWB

    The SELECT statement would return:

    BHP,CWB,.001

    Any help would be greatly appreciated. I've been looking around at different JOIN statements, but can't get it to work with this example.

    Thanks a lot.

    Nick.
    Win A FREE iPhone!

    Tired from working? Funny Things! Laugh the stress away
    Some Funny Jokes | Funny Videos

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,506
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    You are on the right track, JOIN is the way to go. You'll have to join the asx200 table two times to the covar table (using aliasses to identify them):
    Code:
    SELECT
        a1.tickerSymbol AS tickerSymbol1
      , a2.tickerSymbol AS tickerSymbol2
      , covar
    FROM covar
    INNER JOIN asx200 AS a1
    ON a1.id = covar.tId1
    INNER JOIN asx200 AS a2
    ON a2.id = covar.tId2

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    183
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for that! Works perfectly.
    Win A FREE iPhone!

    Tired from working? Funny Things! Laugh the stress away
    Some Funny Jokes | Funny Videos


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
  •