根据子查询数据更新表

时间:2015-06-29 09:50:49

标签: sql ms-access access-vba

我有以下查询从表中提取唯一记录:

SELECT First(t1.[Site Number]) AS [FirstOfSite Number], t1.[Customer Number], First(t1.Address1) AS FirstOfAddress1
FROM tblImport1 AS t1
GROUP BY t1.[Customer Number]
ORDER BY t1.[Customer Number];

我想通过将字段tblimportt1.[Site Number]相关联,根据上述查询更新第二个表格,例如tblimport.[Site Number]

我做了以下查询:

UPDATE tblimport 
INNER JOIN tblimport on  [tblimport].[site number]=[t1].[site number] 
  (SELECT First(t1.[Site Number]) AS [FirstOfSite Number], t1.[Customer Number], First(t1.Address1) AS FirstOfAddress1
  FROM tblImport1 AS t1
  GROUP BY t1.[Customer Number])
set tblimport.address1=t1.address1

但是我得到语法错误。我在哪里错了?

修改

我读了the article suggested,我已经用这种方式修改了查询:

UPDATE D 
set D.address1=t1.address1
FROM tblimport as D
    INNER JOIN (SELECT First(t1.[Site Number]) AS [FirstOfSite Number], t1.[Customer Number], First(t1.Address1) AS FirstOfAddress1  FROM tblImport1 AS t1  GROUP BY t1.[Customer Number])
    ON t1.[Site Number]=D.[Site Number]

但我仍然有语法错误。

0 个答案:

没有答案