Friday, 29 November 2013

INSERT INTO SELECT Statement



selects data from one table and inserts it into an existing table.

We can copy all columns from one table to another, existing table:

INSERT INTO table2
SELECT * FROM table1;

INSERT INTO Customers (CustomerName, Country)
SELECT SupplierName, Country FROM Suppliers;

 

 We can copy only the columns we want to into another, existing table:
 
INSERT INTO table2
(column_name(s))
SELECT column_name(s)
FROM table1;

INSERT INTO Customers (CustomerName, Country)
SELECT SupplierName, Country FROM Suppliers
WHERE Country='Germany';





No comments:

Post a Comment