Inserting from the results of a MySQL SELECT

Posted by on November 7, 2011 in Database, MySQL | 0 comments

If you need a quick way to insert into another table from the results of a query, the best way would be to use the INSERT-SELECT Syntax. It’s quite simple.

INSERT INTO tableA (FieldA, FieldB) (SELECT FieldC, FieldD FROM tableB) ;

Note that field A & C and B & D should have the same data type. Using this method you can avoid any secondary programming language or loops to achieve your insert.

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.

Leave a Comment

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>