SQL Server 多表联合更新方法

复制代码
update Table1 
set BidAgent=x.BidAgent
from Table1 t1,(select c.Id,a.BidAgent from Table1 c
left join Table2 b
on c.PurchaseItemId=b.PurchaseItemId
left join Table3 a
on a.Id=b.ParentId
where a.BidAgent is not null and c.BidAgent is null) x
where t1.Id=x.Id

先将需要的更新数据和待更新的表id查出来放在一个表x上,再关联这个表x更新就好

相关推荐
LUCIAZZZ3 小时前
简单的SQL语句的快速复习
java·数据库·sql
Elastic 中国社区官方博客4 小时前
使用真实 Elasticsearch 进行高级集成测试
大数据·数据库·elasticsearch·搜索引擎·全文检索·jenkins·集成测试
@_@哆啦A梦5 小时前
Redis 基础命令
java·数据库·redis
fajianchen5 小时前
MySQL 索引存储结构
数据库·mysql
想做富婆5 小时前
oracle: 多表查询之联合查询[交集intersect, 并集union,差集minus]
数据库·oracle·联合查询
xianwu5436 小时前
反向代理模块jmh
开发语言·网络·数据库·c++·mysql
Leven1995277 小时前
Flink (十三) :Table API 与 DataStream API 的转换 (一)
数据库·sql·flink
geovindu7 小时前
neo4j-community-5.26.0 create new database
数据库·mysql·neo4j
因特麦克斯8 小时前
索引的底层数据结构、B+树的结构、为什么InnoDB使用B+树而不是B树呢
数据库
java1234_小锋9 小时前
说说Redis的内存淘汰策略?
数据库·redis·缓存