Bri*_*ett 7 sql t-sql sql-server sql-update
晚上好,
实际上,现在是夜晚.晚上11点左右.我的大脑正在关闭,我需要一些帮助,所以我可以完成并回家:)
我有两张桌子 - 桌子a和桌子b.当另外两个字段匹配时,我需要使用表b中字段的值更新表a中的字段.表格没有每条记录的唯一ID :(
基本上,我想这样做:
update a
set importantField =
(select b.importantfield
from b
where a.matchfield = b.matchfield
and a.matchfield2 = b.matchfield2
)
where a.matchfield = b.matchfield
and a.matchfield2 = b.matchfield2
Run Code Online (Sandbox Code Playgroud)
或者至少......我认为这就是我想做的......
有人可以帮帮我吗?
Nic*_*ver 13
您可以通过更新中的联接来执行此操作:
Update a
Set a.importantField = b.importantField
From a Join b
On a.matchfield = b.matchfield
And a.matchfield2 = b.matchfield2
Run Code Online (Sandbox Code Playgroud)