How to Display values from two tables in MySQL???

Discussion in 'MySQL' started by techspott, Apr 20, 2010.

  1. #1
    I have two tables. One has "id" and "title". Other has only "id". How can i automatically add the title with same id of first table alongside the id of second table... Here is a small representation.

    Table 1:
    ======
    Id || Title
    1 The Main Heading
    2 Side Heading

    Table 2:
    ======
    Id || Title
    1 Empty
    2 Empty
    I want the EMPTY in table 2 to be filled automatically by the title that is having the same id in table 1


    Can Anybody help me??

     
    techspott, Apr 20, 2010 IP
  2. NemoPlus

    NemoPlus Peon

    Messages:
    37
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I think it will be something like
    UPDATE table2
    SET Title = (
    SELECT table1.Title
    FROM table1
    WHERE table1.id = table2.id
    )
    Code (markup):
     
    NemoPlus, Apr 20, 2010 IP
  3. techspott

    techspott Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This worked... Thanks a lot... It was very useful...!!
     
    techspott, Apr 20, 2010 IP