我有2个数据库Alpha和Beta。每个数据库都有相同的表"Comments“。Comments表有两个字段: ID和Comments。Alpha.Comments仅填充了ID字段,对应的注释字段为空。Beta.Comments既有ID,也有对应的注释。是否有SQL查询可以更新所有的Alpha.Comments字段与测试版中的适当条目,其中ID匹配?

发布于 2020-09-22 02:19:57
类似于:
update alpha.comments
set comments = (select b.comments from beta.comments b where b.id = comments.id);在SQL Server中,您可以将其表示为:
update a
set comments = b.comments
from alpha.comments a join
beta.comments b
on a.id = b.id;这会以一种不幸的方式处理重复项。它任意选择一个用于赋值,因此不会产生错误。
发布于 2020-09-22 02:22:47
已经有类似此请求的帖子-请查看:
Copy data from one column to other column (which is in a different table)
MySQL: Copy table to another table with an extra column
Join results from tables with same name from different databases
我确信还有其他的,所以你可以找到一个与你正在使用的数据库相关的数据库。
https://stackoverflow.com/questions/63997796
复制相似问题