#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    Two identical mysql tables, one is empty, how to populate it?


    Hi,


    I have one table full of data (imagine 10,000 values)

    => table_1

    ID | name | e-mail (only as example)
    1 |alfaa | e-mail alfaa 1
    2 |alfaa | e-mail alfaa 2
    3 |beta | e-mail beta
    4 |celta |e-mail celta
    ...

    and other identical table with the "e-mail" column empty, and some names that are also contained in table_1, alltough with a different ID


    => table_2 (with 6,000 values)

    ID | name | e-mail
    1 |beta |
    2 |alfaa |
    3 |celta |
    ...

    My question is, how can I populate the empty e-mail column of table_2 with values from e-mail column of table_1 WHERE table_2.name = table_1.name ?

    The IDs are different AND table_1 contains some cases of several e-mails for the same name.

    (well, I also could handle to work without several e-mails for the same name)
    Last edited by Vega5; November 6th, 2013 at 11:38 AM. Reason: correction
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Location
    Portugal
    Posts
    24
    Rep Power
    0
    Make a php file with simple code, and you can make that easily.
  4. #3
  5. SQL Consultant
    Devshed Supreme Being (6500+ posts)

    Join Date
    Feb 2003
    Location
    Toronto Canada
    Posts
    27,203
    Rep Power
    4279
    Originally Posted by webup247biz
    Make a php file with simple code, and you can make that easily.
    this is supremely unhelpful
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Location
    Portugal
    Posts
    24
    Rep Power
    0
    Originally Posted by r937
    this is supremely unhelpful
    If you want I can make you the code, just send me the database I even make the changes between them. Just say
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2013
    Posts
    2
    Rep Power
    0

    I found the solution


    Thanks, I found the solution for this:


    UPDATE table_2, table_1
    SET table_2.`e-mail` = table_1.`e-mail`
    WHERE table_1.`name` = table_2.`name`;

IMN logo majestic logo threadwatch logo seochat tools logo