Copying records in MySQL

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

http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

Copy one record from a table to another

1
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.

Share and Enjoy:
  • Twitter
  • Facebook
  • Digg
  • del.icio.us
  • FriendFeed
  • Google Bookmarks
  • Technorati
MySQL, Technology

If you enjoyed this post, please consider to leave a comment or subscribe to the feed and get future articles delivered to your feed reader.

Comments

2 Responses to “Copying records in MySQL”

Leave Comment

(required)

(required)


Spam protection by WP Captcha-Free