INSERT data from another table using SELECT
suggest changeINSERT INTO Customers (FName, LName, PhoneNumber)
SELECT FName, LName, PhoneNumber FROM Employees
This example inserts all Employees into the Customers table. Because the tables have different columns, name the columns to insert and the columns to select. Corresponding columns need not have the same name, but they must have compatible types. This example assumes that Id is generated automatically (IDENTITY in SQL Server, AUTO_INCREMENT in MySQL, and so on).
If two tables have the same number of columns, in the same order, with compatible types, you can copy every row with:
INSERT INTO Table1
SELECT * FROM Table2
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents