Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2007
    Location
    London
    Posts
    117

    Unanswered: Copy from table1 to table 2 while matching IDs

    Hello all,

    I have two tables. I have simplified it to:

    table1: ID, fromEmail
    table2: ID, fromEmail (blank Column)

    The ID's of table1 and table2 match, there may be repeated in table2. I want the email fields copied to table2 that have the same ID as table1. I have this so far.
    Code:
    INSERT INTO table2.fromEmail WHERE table2.ID=table2.ID
    Of course that won't do it but I don't know how to get the data from table1. Do I use a select statament? I am so thick

    Thank you for any help and direction

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    try this --
    Code:
    UPDATE table1
    INNER
      JOIN table2
        ON table2.ID = table1.ID
       SET table2.fromEmail = table1.fromEmail
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

  3. #3
    Join Date
    Jun 2007
    Location
    London
    Posts
    117
    Aaah that did it! Thank you! You are a blessing to many forums. I've repped you on another forum for this

  4. #4
    Join Date
    Jun 2007
    Posts
    197

    Smile

    Quote Originally Posted by r937
    try this --
    Code:
    UPDATE table1
    INNER
      JOIN table2
        ON table2.ID = table1.ID
       SET table2.fromEmail = table1.fromEmail
    or

    UPDATE table1,table2 SET table2.fromEmail=table1.fromEmail where table2.ID = table1.ID;

  5. #5
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    yeah, but ankur, you're still using an inner join, only using the older, deprecated style instead of the newer, recommended JOIN syntax
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL

Posting Permissions

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