Computer Science/Database

W3Schools SQL | #31 SQL INSERT INTO SELECT 구문

토마토. 2022. 10. 29. 10:24

SQL INSERT INTO SELECT

The SQL INSERT INTO SELECT Statement

한 테이블의 데이터를 복사해서 다른 테이블에 삽입한다.
단, 이 명령문을 이용하려면 원본 테이블과 대상 테이블의 타입이 일치해야 한다.

INSERT INTO SELECT Syntax

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

SQL INSERT INTO SELECT Examples

INSERT INTO Customers (CustomerName, City, Country)
SELECT SupplierName, City, Country FROM Suppliers;
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
SELECT SupplierName, ContactName, Address, City, PostalCode, Country FROM Suppliers;