Learn more
When we work in database, then it is some needs to update table records with another table records. Suppose I was an ISO country table where table has two fields - full name and iso number and I have found updated country table where those two fields are missed. I can update those fields since there is a unique field iso3 country code.
So two tables are new_countries and old_countries, and add two fields in the new table
ALTER TABLE `new_countries` ADD COLUMN `full_name` VARCHAR(150) NULL AFTER `name`, ADD COLUMN `iso_number` INT(5) NULL AFTER `full_name`;
And after then, update query is as like
UPDATE new_countries AS a INNER JOIN old_countries AS b ON a.iso3 = b.iso3 SET a.full_name = b.full_name, a.iso_number=b.number;
Very Simple!
This code can be use for any complex data insert from one table to other table.