
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
Copy all rows of a table to another table in MySQL?
To copy all rows of a table to another table, use the below syntax −
insert into yourTableName2(yourColumnName1,...N) select yourColumnName1,..N from yourTableName1;
Let us first create a table −
mysql> create table DemoTable1(FirstName varchar(100)); Query OK, 0 rows affected (1.11 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1 values('John'); Query OK, 1 row affected (0.31 sec) mysql> insert into DemoTable1 values('Chris'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1 values('Bob'); Query OK, 1 row affected (0.40 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable1;
This will produce the following output −
+-----------+ | FirstName | +-----------+ | John | | Chris | | Bob | +-----------+ 3 rows in set (0.00 sec)
Following is the query to create second table −
mysql> create table DemoTable2 (EmployeeName varchar(100)); Query OK, 0 rows affected (0.78 sec)
Following is the query to copy all rows of a table to another table −
mysql> insert into DemoTable2(EmployeeName) select FirstName from DemoTable1; Query OK, 3 rows affected (0.52 sec) Records: 3 Duplicates: 0 Warnings: 0
Let us now check the records of the 2nd table, wherein we have set the records of 1st table −
mysql> select *from DemoTable2;
This will produce the following output −
+--------------+ | EmployeeName | +--------------+ | John | | Chris | | Bob | +--------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to copy rows from one table to another in MySQL?
- Copy a few columns from a table to another in MySQL
- Simplest way to copy data from one table to another new table in MySQL?
- Move rows from one table to another in MySQL?
- How to copy a table from one MySQL database to another?
- MySQL statement to copy data from one table and insert into another table
- MySQL select query to select rows from a table that are not in another table?
- MySQL command to copy table?
- How can I loop through all rows of a table in MySQL?
- Create a table in MySQL that matches another table?
- How can we delete all rows from a MySQL table?
- MySQL query to copy records from one table to another with different columns
- MySQL - How to count all rows per table in one query?
- Copy column values from one table into another matching IDs in MySQL
- How to copy a table in MySQL using Python?

Advertisements