Your cart
  • IMG
    {{cart_item.name}}
    {{cart_item.variation_attribute_name}}: {{cart_item.variation_attribute_label}}
    {{cart_item.item_unit}}: {{ setCurrency(cart_item.price)}}
    {{ setCurrency(cart_item.price*cart_item.quantity)}}
    Invalid quantity more than stock
Total :
{{setCurrency(cart.sub_total)}}

There is no item in the cart. If you want to buy, Please click here.

How to update one table data from another in MySQL?

Created by :
MySQL
problem
Programming, Software and application
1097
2021-07-19 16:55:07

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.