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 (条件)
基础教程推荐
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 无法解决整理冲突 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
