Update one column from value of another column from another table in MySQL

Update one column from value of another column from another table in MySQL

This can be achieved using a single query with join. We can use the query like this: 

UPDATE table2
INNER JOIN table1 ON table2.id = table1.id
SET table2.column_to_update = table1.column_from_update
WHERE table1.column_from_update != "";

Note:

  • We want to update table2.column_to_update
  • We will update table2.column_to_update from the value of table1.column_from_update
  • table2.id and table1.id is common column in both of the tables.
  • We will update only where table1.column_from_update have some value ( not empty )

Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *