mysql更新一个表里的字段等于另一个表某字段的值

时间:2022-11-11 15:05:34

update a left join c on a.id = c.id set a.body = c.c1 where a.id=c.id;
update zcat as z left join zcat_bak_1212 as zb on z.zcatId = zb.zcatId set z.zcatName = zb.zcatName where z.zcatName is null;

我用到的如下
update z_vnetid__money a left join tab_feeaccount b on a.C_VNETID = b.c_accountcode set a.i_id = b.i_id where a.C_VNETID = b.c_accountcode;

 

 

1. 表结构完全一样
insert into 表1
select * from 表2
2. 表结构不一样(这种情况下得指定列名)
insert into 表1 (列名1,列名2,列名3)
select 列1,列2,列3 from 表2
3、只从另外一个表取部分值
insert into 表1 (列名1,列名2,列名3) values(列1,列2,(select 列3 from 表2));