根据来自其他2个表的联接结果插入一个表 [英] Insert into one table base on join result from 2 other table
本文介绍了根据来自其他2个表的联接结果插入一个表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MySQL中有3个表:def_table,spot_table,tag_mapping_spot_table.
I have 3 tables in MySQL: def_table,spot_table,tag_mapping_spot_table.
def_table
tag_id tag_ja
2010490043 アラバマ・アンド・ガルフ・コースト鉄道
2010680003 american_football、サッカー、スポーツ
2010970036 ノーフォークマツの種
......... ..........
spot_table
spot_id spot_name
1 NULL
2 NULL
3 NULL
... ....
tag_mapping_spot_table
spot_id tag_id
1 2010490043
2 2010680003
3 2010970036
.... .....
我要做的就是基于tag_id列连接"tag_mapping_spot_table"和"def_table",然后基于spot_id将结果与"spot_table"连接.我想将结果从tag_ja列添加到spot_name列
All I want to do is join "tag_mapping_spot_table" and "def_table" base on column tag_id and then join the result with "spot_table" base on spot_id.I want to put the result from column tag_ja to column spot_name
类似
insert into spot(spot_name) where spot_id = b.spot_id
(select a.tag_ja,b.spot_id from def_table a join tag_mapping_spot b
on a.tag_id = b.tag_id
这是我要在spot_table中获得的结果
Here is the result I want in spot_table
spot_id spot_name
1 アラバマ・アンド・ガルフ・コースト鉄道
2 american_football、サッカー、スポーツ
3 ノーフォークマツの種
推荐答案
您需要UPDATE
(而不是INSERT
):
更新文档
You need a UPDATE
(not INSERT
):
UPDATE DOCS
UPDATE spot_table ST
INNER JOIN tag_mapping_spot_table c ON c.spot_id = ST.spot_id
INNER JOIN def_table b ON b.tag_id = c.tag_id
SET ST.spot_name = b.tag_ja
这篇关于根据来自其他2个表的联接结果插入一个表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文