

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Take all records from one MySQL table and insert it to another?
For this, you can use the concept of CREATE TABLE AS SELECT statement. Let us first create a table −
mysql> create table DemoTable1518 -> ( -> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> EmployeeName varchar(20) -> )AUTO_INCREMENT=101; Query OK, 0 rows affected (0.69 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1518(EmployeeName) values('John Doe'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1518(EmployeeName) values('John Smith'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable1518(EmployeeName) values('David Miller'); Query OK, 1 row affected (0.14 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1518;
This will produce the following output −
+------------+--------------+ | EmployeeId | EmployeeName | +------------+--------------+ | 101 | John Doe | | 102 | John Smith | | 103 | David Miller | +------------+--------------+ 3 rows in set (0.00 sec)
Following is the query to take all records from one MySQL table and insert it to another −
mysql> create table DemoTable1519 as select * from DemoTable1518; Query OK, 3 rows affected (0.62 sec) Records: 3 Duplicates: 0 Warnings: 0
Display all records from the table using select statement −
mysql> select * from DemoTable1519;
This will produce the following output −
+------------+--------------+ | EmployeeId | EmployeeName | +------------+--------------+ | 101 | John Doe | | 102 | John Smith | | 103 | David Miller | +------------+--------------+ 3 rows in set (0.00 sec)
- Related Questions & Answers
- Insert data from one table to another in MySQL?
- MySQL statement to copy data from one table and insert into another table
- How to SELECT fields from one table and INSERT to another in MySQL?
- Insert from one table with different structure to another in MySQL?
- MySQL query to copy records from one table to another with different columns
- Insert data from one schema to another in MySQL?
- How do I INSERT INTO from one MySQL table into another table and set the value of one column?
- How to insert values from one table into another in PostgreSQL?
- Find records from one MySQL table which don't exist in another?
- Fetch maximum ID value from the first table and insert to all the IDs in another table with MySQL INSERT INTO select?
- Move rows from one table to another in MySQL?
- A single MySQL query to insert records (not all) in the second table from the first table
- Delete all records from a table in MySQL?
- Delete all the records from a MySQL table?
- Insert values in a table by MySQL SELECT from another table in MySQL?
Advertisements