Weblog of Nazly Ahmed

Nazly Ahmed

Nazly Ahmed

Web Developer. PHP Addict. Wordpress Hacker. FOSS Enthusiast. (Micro)Blogger. Photo Hobbyist. Cricket Fanatic. Husband. Dad.

Copying records from one table to another can be a very basic requirement. But writing queries to perform this task can be bit of a work around. But there is a very simple query to get this done.

Its by using INSERT … SELECT

Copy one record from a table to another

INSERT INTO `dest_table` SELECT * FROM source_table WHERE id = '10'

It can be very simple as this. Even multiple records can be copied from a single table or several tables. If I'm not mistaken INSERT … SELECT works on MySQL versions 4.1 and above.

Posted on 17th May 2007 11:42:05