如果您的資料在其他表中已經存在,可以通過INSERT SELECT FROM
將資料複製到另外一張表。
文法
INSERT INTO table_name
[( column_name [, …] )]
query;
參數
column_name
:列名,如果需要將源表中的部分列資料插入到目標表中,SELECT子句中的列必須與INSERT子句中列的順序、資料類型一致。query
:可以是SELECT FROM TABLE
或者SELECT FROM VIEW
。
樣本
以指定列名的方式,從CUSTOMER表中複製某幾列資料到NEW_CUSTOMER表中。
INSERT INTO new_customer (customer_id, customer_name, phone_num) SELECT customer_id, customer_name, phone_num FROM customer WHERE customer.customer_name = '楊過';
不指定列名,從CUSTOMER表中複製所有列資料到NEW_CUSTOMER表中。
INSERT INTO new_customer SELECT customer_id,customer_name,phone_num,city_name,sex,id_number,home_address,office_address,age,login_time FROM customer WHERE customer.customer_name = '楊過';