Results 1 to 7 of 7
  1. #1
    user9 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2013
    Location
    US
    Posts
    43

    Update One Field in a Table from Another

    I have two tables - Ledger and RWV. Both have the primary key RV. I'm trying to update field "Amount" in RWV from the field "Amount" in Ledger, but change no other fields.



    Here's what I have that is not returning anything:

    Code:
    UPDATE Ledger LEFT JOIN RWV ON Ledger.RV = RWV.RV SET RWV.Amount = Ledger.Amount
    WHERE (((RWV.RV)=[Ledger].[RV]));
    Should be so simple, just need another set of eyes. Thanks in advance!

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    What are you expect to return? "Update" does not return anything except a count of how many records are updated.

    You are also using "LEFT JOIN" instead of "INNER JOIN".
    The "LEFT JOIN" with "(((RWV.RV)=[Ledger].[RV]))" is same as just "INNER JOIN".

    UPDATE Ledger INNER JOIN RWV ON Ledger.RV = RWV.RV SET RWV.Amount = Ledger.Amount;

  3. #3
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    Why are you duplicating data?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  4. #4
    orange's Avatar
    orange is offline Moderator
    Windows XP Access 2003
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,870
    Agree with the others --what ae you doing?
    Can you step back and tell us in plain English what you are trying to accomplish?

  5. #5
    user9 is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Oct 2013
    Location
    US
    Posts
    43
    Table 1 is the project master with 25 columns - including "RV". Table 2 is new and has 2 columns - "RV" and "Amount". Both have the same Primary Key - "RV".

    I have added an "Amount" column to Table 1. Where RV matches on both tables, I need to populate Table 1 with the value from Table 2.

    There are no duplicates, "Amount" did not previously exist in Table 1. It's a new field available to add to the master table.

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,771
    The duplication is having Amount in two tables. If both tables are retained then why duplicate Amount into Table1 instead of just using a SELECT query that joins the two tables? Is this UPDATE a one-time event and then Table2 will be elminated? If RV is primary key in both tables then this is a 1-to-1 relationship and really should be one table. If RV is actually a foreign key in Table1 and Table2 is a lookup table then is Amount in Table2 subject to change in the future and you want to commit the current value to Table1 records?

    There was no need for the WHERE clause in the original query. Not sure why the LEFT JOIN update failed.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  7. #7
    rpeare is offline VIP
    Windows XP Access 2003
    Join Date
    Jul 2011
    Posts
    5,441
    That's not explaining WHY. You are explaining WHAT you want to do. If your tables have a 1 to 1 relationship you shouldn't need to carry the same piece of information from one table to another.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 05-17-2013, 12:53 PM
  2. Replies: 5
    Last Post: 11-01-2012, 09:26 AM
  3. Replies: 12
    Last Post: 03-17-2012, 04:46 AM
  4. Replies: 1
    Last Post: 08-31-2011, 04:03 PM
  5. Update field in table after update on a subform
    By jpkeller55 in forum Queries
    Replies: 3
    Last Post: 09-30-2010, 08:02 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums