MySQL insert into select

This SQL statement to be used to insert data into a table from another different table.

INSERT INTO table1 (field1)
  SELECT table2.field2 FROM table2 
  WHERE table2.field2 > 100;

Be careful with ambiguous fields. So put the table name in front of the field name.
Also be careful with duplicate data inserted to the table.

Leave a Reply

Your email address will not be published. Required fields are marked *