INSERT SELECT FROM (Version 2.0)

更新时间:
复制 MD 格式

AnalyticDB for MySQL 2.0 lets you copy data from an existing table by running a query.

Syntax

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

Parameters

column_name: The name of the column. If you insert data into only specific columns of a target table, ensure that the columns in the SELECT clause match the columns in the INSERT clause in both order and data type.

Examples

  • Copy data from specific columns of the order table to the new_order table.

      INSERT INTO new_order (customer_id, order_id, order_time, order_amount, order_type, address, city, order_season)
      SELECT customer_id, order_id, order_time, order_amount,order_type, address, city, order_season FROM order
      WHERE order.order_season = '201804';
  • Copy all data from the order table to the new_order table.

      INSERT INTO new_order
      SELECT customer_id, order_id, order_time, order_amount, order_type, address, city, order_season  FROM order
      WHERE order.order_season = '201807';