+3 votes
in Databases by (60.2k points)
How can I select all rows from table1 and insert into table2 using SQL. I am using MySQL database.

1 Answer

+1 vote
by (355k points)
selected by
 
Best answer

If you want to copy all columns from table1 to table2, you can use the following query:

INSERT INTO table2
SELECT * FROM table1
WHERE condition; 

If you want to copy some selected columns from table1 to table2, you can use the following query:

INSERT INTO table2 (column1, column2, column3, ...)
SELECT column1, column2, column3, ...
FROM table1
WHERE condition;

Related questions


...