Friday, December 13, 2013

insert into table from another table

Along the way, we want to select some data from one table A and insert into another table B. Directly we can simply fire the following query to get our desired data in the right place.

sql> insert into B (field_1_B, field_2_B, field_3_B)  select field_1_A, field_2_A, field_3_A from A;

Suppose now that these tables are from different databases inside mysql.

A is inside database DB1  and B inside databae DB2, then

sql> insert into DB2.B (field_1_B, field_2_B, field_3_B)  select field_1_A, field_2_A, field_3_A from DB1. A;

and so is it.

No comments:

Post a Comment