Update table a from table b where (conditions)(从表 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 (条件)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:从表 b 更新表 a (条件)


基础教程推荐
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 带更新的 sqlite CTE 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 带有WHERE子句的LAG()函数 2022-01-01