使用 SQL 从另一个 Access 表更新 MSAccess 表 [英] Update MSAccess table from another Access table using SQL

查看:39
本文介绍了使用 SQL 从另一个 Access 表更新 MSAccess 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Final 中的值更新表 Original.我是 SQL 的新手,但我已经在这方面工作了两个小时,试图更改各种示例以满足我的需要.我使用的是 Access 2007.

I am trying to update table Original with the values in Final. I'm a newb to SQL, but I have been at this for two hours trying to change various samples to fit my needs. I am using Access 2007.

UPDATE 
  Original o
SET 
  o.[Assest Description] = (
    SELECT f.[Assest Description] FROM Original o, Final f 
    WHERE o.[Assest No] = f.[Assest No])
WHERE o.[Assest No] = Final.[Asset No]

推荐答案

我不确定您的 select 语句是否只返回一行.如果您想使用 select 语句对表进行赋值操作,您必须确保它只返回一行.

I'm not sure your select statement returns only one row. If you want to perform an update on a table using a select statement for assignment, you must be sure that it returns only one row.

除此之外,您可以考虑下一个解决方案:

Besides that, you may consider the next solution:

update 
   Original as o
   inner join Final as f on o.[Assest No] = f.[Assest No]
set
   o.[Assest Description] = f.[Assest Description]

请注意,只有当 [Assest no] 都是 OriginalFinal 表中的唯一键时,这才能正常工作,并且它们适当相关.

Notice that this will only work correctly if both [Assest no] is a unique key in both Original and Final tables, and they are properly related.

这篇关于使用 SQL 从另一个 Access 表更新 MSAccess 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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