根据多个表的数据更新单个表 SQL Server 2005,2008 [英] Update a single table based on data from multiple tables SQL Server 2005,2008

查看:32
本文介绍了根据多个表的数据更新单个表 SQL Server 2005,2008的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要使用表 two 中的数据更新表 one.表一和表二不与任何公共列相关.three表与two表相关.

I need to update table one using data from table two. Table one and two are not related by any common column(s). Table three is related to table two.

例如:表一(reg_det表)

Ex : table one(reg_det table)

reg_det_id | reg_id | results
101        | 11     | 344

表二:(临时表)

venue                    | results
Anheim convention center | 355

表三(regmaster-tbl)

Table three (regmaster-tbl)

reg_id| venue
11    | Anaheim convention center

我需要使用表二中的数据更新表一中的结果列.但是表一和表二不相关.如上所示,表二和表三以及表一和表三是相关的.任何人都可以请提出任何想法!我需要表一中的结果值为 355 并且该数据来自表 2,但这两个是不相关的,它们可以使用表三相关联.如有混淆,请见谅!

I need to update results column in table one using data from table two. But table one and two are not related. Table two and three and table one and three are related as you can see above. Can anyone please suggest any ideas! I need the results value to be 355 in table one and this data is coming from table 2, but these two are unrelated, and they can be related using table three. Sorry if it is confusing!

推荐答案

相当简单:

UPDATE T1
SET result = t2.results
FROM [table one] T1
INNER JOIN [table three] t3
 on t1.reg_id = t3.reg_id
INNER JOIN [table two] T2
 on t2.venue = t3.venue

这篇关于根据多个表的数据更新单个表 SQL Server 2005,2008的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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