Matching a value then transferring data from one table to another

Discussion in 'PHP' started by rtblizz, Apr 3, 2012.

  1. #1
    I know the Insert sql:

    
    
    INSERT INTO table1  (value,value,value) SELECT table2.value, table2.value, table2.value FROM  table2;
    
    
    PHP:


    I have this situation

    Table 1 and table 2 have 4 fields that are the same.

    St - Zip - Longitude - Latitude

    the table1 has values like this:

    St Zip Longitude Latitude
    MD 21108 101.5638 89.3472
    MD 21061 102.6348 90.0374
    MD 21062 102.1256 90.1259

    Table 2 has these values:

    St Zip Longitude Latitude
    MD 21108
    MD 21061
    MD 21062

    What I need to do is take the Zip values with the attached Longitude and Latitude value from table one and match it up with the Zip value in table 2 so i can insert the Longitude and Latitude into table 2. Currently those values do not exist in table 2..

    I need to know how to write a query to have this work??
     
    rtblizz, Apr 3, 2012 IP
  2. blacknet

    blacknet Active Member

    Messages:
    709
    Likes Received:
    16
    Best Answers:
    2
    Trophy Points:
    70
    #2
    Perhaps it's just me, but Table1 appears to already include all the info of Table2.

    Regardless, you want a SELECT with an INNER JOIN on the Zip from both tables. A quick google for MySQL Joins will provide all the info you need to do it, and answer any further questions.
     
    blacknet, Apr 3, 2012 IP