mysql多表关联的新增和修改操作

1.多表的新增操作

需求:从一个表查出的字段插入到另一个表

示例:将loit_bear表的type_code和type_name的字段值全部分别新增到loit_dict表的dict_code和dict_name字段

INSERT INTO loit_dict (dict_code,dict_name)
select type_code, type_name from loit_bear

2.多表的修改操作

需求:从一个表查出指定字段值更新到另一个表的指定字段中

示例:将a表的type_name字段值修改为b表的dict_name字段值,其中a表的dict_id和b表的id是关联字段

update loit_bear a
inner join loit_dict b
on a.dict_id = b.id
set a.type_name = b.dict_name
posted @ 2023-07-21 10:28  木糖醇困了  阅读(1095)  评论(0)    收藏  举报