+ Almost all quality improvement comes via simplification of design, manufacturing... layout, processes, and procedures.

February 8, 2010, 6:25 pm

mysql update from another table

July 3, 2007

Recently I needed to update a bunch of rows in mysql with information from another table. I will explain how to do this simple process.

  1. Open up phpmyadmin or similar database editor
  2. view the sql query below
Code (sql)
  1.  
  2. UPDATE updatefrom p, updateto pp
  3. SET pp.last_name = p.last_name
  4. WHERE pp.visid = p.id

Lets say we have 2 tables one named main and one named updateto and one named updatefrom, In the first line we assign variables to these t tables (p and pp) from there we can call column names using this format table.columname. If we had first_name and last_name in both tables and wanted to update the “updateto” table with the info from “updatefrom” this is how you would write it.

Posted by Anthony under PHP, Web Technology, mysql | Comments (4)

4 Comments »

  1. Thanks! :-)

    That was exactly what I was looking for!

    Regards,
    Evert

    Comment by Evert — May 22, 2008 @ 4:06 am

  2. thanx so much, Help me much :)

    Comment by Mahshid — February 21, 2009 @ 8:44 pm

  3. thank you! thank you! thank you!

    Saved me from countless hours of more frustration :)

    It’s so easy when you see it too!

    Comment by Sandy — February 27, 2009 @ 11:50 am

  4. I can’t believe it was that easy. You are the person. Your code explained things well. Thanks.

    Comment by Brandon Buttars — January 26, 2010 @ 5:23 pm

RSS feed for comments on this post. | Trackback

Leave a comment

XHTML ( You can use these tags): <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> .

*
To prove that you're not a bot, enter this code
Anti-Spam Image