Blog Detail Pic

Update One Table with Another In MySQL

by Kwilio | Apr 16, 2022

This tutorial will show you how to easily update one table with values from another table in MySQL. We will use INNER JOIN using foreign key to update table_a with values from table_b.

I will assume at this stage you already know how to create tables so I will not provide a test table schema but instead provide the codes to accomplish the task.

UPDATE table_a a
  inner join table_b b on
        b.table_a_id =
  SET a.column_1=b.table_b_column_2, a.column_3=b.table_b_column_1

The key items to note are the columns that are joined b.table_a_id = and the columns who's values we are updating. In this case we are updating two columns from table_a (a.column_1, a.column_3) with values from the two columns from the joined table.

That's it! Easy right?