To copy record from one table to another table INSERT INTO SELECT statement is used.
In this statement the data types in source and target tables should match.
Note => It will not affect the existing records in the target table.
Syntax:
INSERT INTO target_table
SELECT * FROM source_table
WHERE condition; DEMO STUDENTS TABLE:
| Roll_No | Name | Marks |
| 1 | Dev | 35 |
| 2 | Ayush | 45 |
| 3 | Ram | 55 |
| 4 | Pyush | 65 |
| 5 | Nazim | 75 |
Example:
INSERT INTO clg
SELECT * FROM students; This will copy the records from students table to clg table:
| Roll_No | Name | Marks |
| 1 | Dev | 35 |
| 2 | Ayush | 45 |
| 3 | Ram | 55 |
| 4 | Pyush | 65 |
| 5 | Nazim | 75 |
Selected columns can also can be copied from one table to another table by selecting them using SELECT statement.