Query from 2 tables- Please HELP

Discussion in 'MySQL' started by KingCobra, Jul 29, 2010.

  1. #1
    I have 2 tables named 'user_table' and 'country_table'.

    (user_table)
    name cc dd
    ----- -- --
    AAAA US IN
    BBBB UK US
    CCCC US US

    (country_table)
    code name
    ---- -----
    US United States
    UK United Kingdom
    AU Australia

    I want to run a query that produce the result like the following

    name cc_country dd_country
    ----- ---------- -----------
    AAAA United States India
    BBBB United Kingdom United States
    CCCC United States United States

    What will be the query?
    My friends please help me.
     
    KingCobra, Jul 29, 2010 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    
    SELECT user_table.name,
           country_table_1.name,
           country_table_2.name
    FROM   user_table
           INNER JOIN country_table AS country_table_1
             ON user_table.cc = country_table.code
           INNER JOIN country_table AS country_table_2
             ON user_table.dd = country_table.code  
    Code (markup):
     
    jestep, Jul 29, 2010 IP