[英]copy data from one table to another where column count is different
我有兩張桌子
table_1
-------
id,name,address
table_2
-------
id,name,address,phone_no
我想將所有數據從表_1復制到表_2。 當我執行以下查詢時,它將引發錯誤。
mysql> insert into table_2 select * from table_1;
ERROR 1136 (21S01): Column count doesn't match value count at row 1
指定列:
insert into table_2 (id, name, address) select (id, name, address) from table_1
當然, id
必須是可插入的(不是生成的值), phone_no
需要允許為null
值(否則,您必須指定默認值)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.