从表 b 更新表 a 其中(条件) [英] Update table a from table b where (conditions)

查看:28
本文介绍了从表 b 更新表 a 其中(条件)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上,

实际上,现在是晚上.晚上11点左右.我的大脑正在关闭,我需要一些帮助才能完成并回家:)

Actually, it's night. About 11pm. My brain is shutting down and I need a bit of help so I can finish and go home :)

我有两个表 - 表 a 和表 b.当其他两个字段匹配时,我需要使用表 b 中字段的值更新表 a 中的字段.这些表没有每条记录的唯一 ID :(

I have two tables - table a and table b. I need to update a field in table a with the value from a field in table b when two other fields match. The tables don't have a unique id for each record :(

基本上,我想这样做:

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

或者至少......我认为这就是我想做的......

Or at least... I think that's what I want to do...

有人可以帮我吗?

推荐答案

您可以通过加入更新来做到这一点:

You can do this via a join in the update:

Update a
Set a.importantField = b.importantField
From a Join b 
  On a.matchfield = b.matchfield
  And a.matchfield2 = b.matchfield2

这篇关于从表 b 更新表 a 其中(条件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆