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 = 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.

15 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 = p.id SET pp.last_name = p.last_name
    WHERE pp.status = ‘active’…

  4. Топ 10 лучших онлайн-казино, которые заняли первые места в рейтинге игр на наличные деньги, доверия и других значимых критериев 2024 лучшие казино

  5. Арктика – северная полярная область Земли, включающая окраины материков Евразии и Северной Америки, почти весь Северный Ледовитый океан с островами и прилегающие к нему части Атлантического и Тихого океанов. Название её происходит от греческого слова arctos (медведь) и связано со звёздами: Полярная звезда, находящаяся почти точно в зените над Северным полюсом, принадлежит к созвездию Малая Медведица.

Leave a Comment