+3 votes
in Databases by (54.6k 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 (347k 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


...