Multiple Insert Into a Table From Another Table

A query for transferring data from one table to another.

{code type=”php”}

INSERT INTO table2  (field1,field2,field3)
SELECT col1, col2, col3 FROM table1 WHERE table1_field2 = 10

{/code}

In this query, we want to transfer the data from table1whose col2fields are equal to 10.

Origin Table table1

col1col2col3
110Apple
210Banana
36Orange
410Cherry

Destination Table table2

field1field2field3

After the query, table2 would look something like this:

field1field2field3
110Apple
210Banana
410Cherry

HTH

Recommended Posts