how to join two tables in database

Discussion in 'Databases' started by seo-india, Aug 16, 2010.

  1. #1
    how to join two different tables in database
     
    seo-india, Aug 16, 2010 IP
  2. koko5

    koko5 Active Member

    Messages:
    394
    Likes Received:
    14
    Best Answers:
    1
    Trophy Points:
    70
    #2
    Please elaborate and provide tables' structure.
     
    koko5, Aug 17, 2010 IP
  3. dreteh

    dreteh Member

    Messages:
    514
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    33
    #3
    I am assuming this is what you are looking for:

    SELECT *
    FROM table1
    INNER JOIN table2
    ON table1.id = table2.id
     
    dreteh, Aug 17, 2010 IP
  4. Carol Smith

    Carol Smith Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    i doubt...
     
    Carol Smith, Aug 17, 2010 IP
  5. joomclan

    joomclan Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    here is inner join

    SELECT t1.name, t2.salary
    FROM employee AS t1 INNER JOIN info AS t2 ON t1.name = t2.name;
     
    joomclan, Sep 2, 2010 IP
  6. Vicbowling

    Vicbowling Peon

    Messages:
    23
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Tizag has some good examples - http://www.tizag.com/mysqlTutorial/mysqljoins.php
    http://www.tizag.com/mysqlTutorial/mysqlleftjoin.php
     
    Vicbowling, Sep 3, 2010 IP
  7. retreet

    retreet Guest

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    we can using "JOIN", "LEFT JOIN", "RIGHT JOIN" to join the one tables and the data from multiple tables by single query.

    Here i have joined 3 tables in one query
    SELECT e.name,g.name,c.name FROM employee as e LEFT JOIN group as g USING(`group_id`) LEFT JOIN company as c USING( `company_id` )
     
    retreet, Sep 3, 2010 IP