dats dats - 1 year ago 44
SQL Question

How do i copy data from one table to another table?

I have 2 tables, country and division with the ff schemas:

country division
----------- ------------
countrycode divisioncode
contryname countrycode
divisionname


I want to copy data from the country table into the division table where countrycode goes into divisioncode and countrycode in division table and countryname going into divisionname

For ex, US - United States goes into the division table as US, US, United States.

Answer Source

Use INSERT INTO ... SELECT

Query

INSERT INTO division(divisioncode, countrycode, divisionname)
SELECT countrycode, countrycode, countryname
FROM country;