gpt4 book ai didi

MySQL:使用其他表修复数据

转载 作者:可可西里 更新时间:2023-11-01 07:58:37 25 4
gpt4 key购买 nike

我需要使用表“tag2”修复表“tag”中的数据,

通过匹配“tag.id”和“tag2.id”,如果匹配则用“tag”表中的“tag.name”替换“tag2.name”,

表结构:

标签:

id     name
1 test
2 test
3 test
4 Tom hancks
5 test
6 amazon
7 car
8 BMW
9 search

标签 2:

id     name
1 Google
2 yahoo
3 Microsoft
4 Tom hancks
5 facebook

像这样返回“标签”表:

标签:

id     name
1 Google
2 yahoo
3 Microsoft
4 Tom hancks
5 facebook
6 amazon
7 car
8 BMW
9 search

最佳答案

您可以使用内部联接来完成。

 update tag  inner join tag2
on tag.id = tag2.id
set tag.name = tag2.name

关于MySQL:使用其他表修复数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29839551/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com