|
|
How to copy record from one table to another? - Mysql
|
Views : 1939
|
|
Tagged in : Mysql
|
|
|
Report This Scrap as Inappropriate We request you to choose the appropriate categroy and subcategory that suits your
objectionable concern about the scrap, So that our team can review and find out whether it violates our Guidelines or the
scrap is not suitable for all viewers.
|
We can copy records from one table to another using INSERT....SELECT
SYNTAX:
INSERT INTO tbl_name [(col_name,...)]SELECT ...
[ ON DUPLICATE KEY UPDATE col_name=expr, ... ]
|
Example:
I have table test1 with:
id Type Name
1 A Ram
2 B Raj
3 C San
I want to create a table with inserting the records from the table test1.
mysql> CREATE TABLE test2(id int(11) PRIMARY KEY auto_increment, Name VARCHAR(20));
|
mysql> INSERT INTO test2(Name)SELECT Name FROM test1;
|
The above query helps to copy the record Name from the table test1 to test2.
|
mysql> SELECT * FROM test2;
|
id Name
1 Ram
2 Raj
3 San
|
|
By Sanju, On - 2008-07-03 |
|
|
|
|