All Products
Search
Document Center

AnalyticDB:INSERT SELECT FROM

Last Updated:Mar 28, 2026

Copies rows from one table into another using a SELECT subquery.

Usage notes

AnalyticDB for MySQL does not guarantee that rows are written to the destination table in the same order as the results returned by the INSERT INTO SELECT statement.

Syntax

INSERT INTO table_name
[( column_name [, ...] )]
query;

Parameters

ParameterDescription
column_nameThe name of the destination column. If specified, the columns in the SELECT subquery must match the columns in the INSERT INTO clause in the same order and with the same data types.
queryThe SELECT subquery to run. Supported forms: SELECT FROM TABLE and SELECT FROM VIEW.

Examples

Insert specific columns

Insert customer_id, customer_name, and phone_num from the customer table into the new_customer table.

INSERT INTO new_customer (customer_id, customer_name, phone_num)
SELECT customer_id, customer_name, phone_num FROM customer
WHERE customer.customer_name ='Alan';

Insert all columns

Insert all columns from the customer table into the new_customer table without specifying column names.

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 ='Alan';