Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update MSAccess table from another Access table using SQL

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]
like image 351
Hamptonite Avatar asked Dec 20 '22 15:12

Hamptonite


2 Answers

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]

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.

like image 172
Barranka Avatar answered Mar 07 '23 03:03

Barranka


Try this

UPDATE o 
SET o.[Assest Description] =  f.[Assest Description]
FROM Original o, Final f WHERE o.[Assest No] = f.[Assest No]
like image 24
cmsjr Avatar answered Mar 07 '23 04:03

cmsjr