Results 1 to 4 of 4

Thread: sql join

  1. #1
    Join Date
    Aug 2006
    Posts
    39

    Unanswered: sql join

    There are two tables:
    for example:
    tblCurrencies
    CurrencyID, Name
    1 USD
    2 GBP
    3 CAD
    4 JPY


    tblCurrencyPairs
    CurrencypairID, Currency1ID, Currency2ID
    1 4 1
    2 1 3
    5 2 1

    How can I write a sql query to show the fields in tblCurrencypairs, but to show the currencyNames concatenated instead of their IDs. So table tblCurrencyPairs should show something like:
    CurrencypairID, CurrencyPairs
    1 JPYUSD
    2 USDCAD
    5 GBPUSD

    Thanks

  2. #2
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    join to tblCurrencies twice using table aliases.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  3. #3
    Join Date
    Aug 2006
    Posts
    39
    hi,
    A simple example would be appreciated please.
    Thanks

  4. #4
    Join Date
    Mar 2005
    Location
    Netherlands
    Posts
    280
    Eeeeh, something like this:
    Code:
    SELECT CurrencypairID, c1.name + c2.name
    FROM tblCurrencyPairs cp
       INNER JOIN tblCurrencies c1 ON c1.CurrencyID = cp.Currency1ID
       INNER JOIN tblCurrencies c2 ON c2.CurrencyID = cp.Currency2ID

Posting Permissions

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