INSERT INTO … SELECT without detailing all columns

前端 未结 11 1294
不知归路
不知归路 2020-12-08 09:50

How do you insert selected rows from table_source to table_target using SQL in MySQL where:

  • Both tables have the same schema
11条回答
  •  [愿得一人]
    2020-12-08 10:44

    Column names have to be specified -

    INSERT INTO table_target SELECT NULL, column_name1, column_name2, column_name3, ...
      FROM table_source;
    

    Just pass NULL as a value for the auto-increment id field.

提交回复
热议问题