INSERT SELECT FROM
更新時間:
如果您的數據在其他表中已經存在,可以通過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 = '楊過';
文檔內容是否對您有幫助?