mysql update from another table

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
UPDATE updatefrom p, updateto pp 
SET pp.last_name = p.last_name 
WHERE pp.visid =

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.

13 thoughts on “mysql update from another table”

  1. thank you! thank you! thank you!

    Saved me from countless hours of more frustration 🙂

    It’s so easy when you see it too!

  2. Found this after a long search.

    This should not be so difficult to find – in 1984 dBase II had this as a simple syntax. And so did all the subsequent DB programs.

    Thank you for your extremely helpful and elegant solution.

    This is one MYSQL command that is entirely intuitive.

    Please keep up the great work – very much appreciated by us older chaps – I started in 1964 at Monash University in Melbourne Australia, start of a lifelong fascination with numbers.

  3. This will also do…

    UPDATE updateto pp INNER JOIN updatefrom p
    on pp.visid = SET pp.last_name = p.last_name
    WHERE pp.status = ‘active’…

Leave a Comment