Home » Database » How to copy table rows to another table in MySQL

How to copy table rows to another table in MySQL

MySQL is perhaps one of the most widely used databases in the world especially when almost all free source content management systems and blogging platforms heavily rely upon MySQL. If you are a self publisher or a blogger there is a great chance that you’re dabbling with MySQL.

You can copy rows from one MySQL table to another using a condition or you can copy the entire set of rows. In order to copy rows from one table to another MySQL table both the tables must have the appropriate columns in order for the operation to execute successfully. Let us assume that you have a “table1” and “table2” and “table1” contains some information about certain cities and you need to copy information pertaining to one single city into “table2”. This is how you use the MySQL command:

INSERT INTO table2 (restaurant_id, restaurant_name, restaurant_location) SELECT FROM table1 restaurant_id, restaurant_name, restaurant_location WHERE restaurant_city=”Honolulu”

That’s it. You can use this MySQL command to copy table rows from one table to another. You can easily customize this command according to your individual requirement.