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 (条件)


- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01