You can execute the INSERT SELECT FROM statement to copy records from one table to another.

Syntax

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

Parameters

  • column_name: the name of the column. If you only want to copy data from certain columns of the source table to the target table, the columns specified in the SELECT clause must have the same sequence and data types as those specified in the INSERT clause.
  • query: the SELECT FROM TABLE or SELECT FROM VIEW statement.

Example

  • Copy data from only the specified columns of the customer table to the new_customer table by specifying the column names.
    INSERT INTO new_customer (customer_id, customer_name, phone_num)
    SELECT customer_id, customer_name, phone_num FROM customer
    WHERE customer.customer_name = 'Alan';                
  • Copy data from all columns of the customer table to the new_customer table and do not specify the 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';