Results 1 to 9 of 9
  1. #1
    joethall is offline Novice
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Posts
    9

    Merge two tables

    How can I merge the records from table B into table A ignoring fields not in A?

    The two tables are largely the same but with some significant differences.


    I want the resultant Table A records to have only the fields from Table A.

    I need to end up with all records from Table A preserved and additional records
    created in Table A from Table B where the index fields are different.

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Run an INSERT action SQL or simply copy/paste. Do you have compound index set to unique? Duplicates will not be allowed, records just won't insert.
    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.

  3. #3
    joethall is offline Novice
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Posts
    9
    I did not expect I could send files but here they are!
    tblCrewsArchiev2018 needs to be merged into tblCrewsArchive
    retaining only the non-2018 fields.
    Attached Files Attached Files

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    As far as I can see, both tables have the same IHSAID keys for 2018. So you don't need to add new records, but update existing?

    I looked at IHSAID 13622 in both tables. Data looks same. Don't know what you mean by 'non-2018' fields. Both tables have same fields. Provide a specific example of what you want to accomplish.
    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.

  5. #5
    joethall is offline Novice
    Windows 7 Access 2007
    Join Date
    Jun 2010
    Posts
    9
    Ooops! I fat-fingered the creation of the zip file I sent earlier and you got two copies of the same tables.
    I think that you will now see that the 2018 file has a bunch of fields that are not in the non-2018 table.
    CClast_, CCfirst_ are two such fields.

    So that you don't have to look it up, I need for the records in the 2018 table to be inserted into the non-2018 table where the IHSAID (primary key for both) is not already present.

    For the occurrence of a new IHSAID, only the 2018 fields that match the non-2018 table should be copied. If the IHSAID from 2018 is already present in non-2018 then simply skip that field.

    When done, all the records should have only the fields in the non-2018 table.

    Thanks

    Joe
    Attached Files Attached Files

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    This is far from a normalized data structure and the query will be a very long statement. The field names are not all exactly same. Roughly:

    INSERT INTO tblCrewsArchive(IHSAID, <list the fields you want to poplulate>) SELECT IHSAID, <list the fields you want to pull from> FROM tblCrewsArchive2018

    Since IHSAID in tblCrewsArchive is set as Indexed no duplicates, no duplicate IHSAID will transfer, entire 2018 record will be omitted.

    "If the IHSAID from 2018 is already present in non-2018 then simply skip that field" doesn't really make sense. As already stated, entire record will not transfer.

    Alternative is VBA code opening and manipulating recordset objects.
    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
    Marvelick is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    2
    I have similar question. I have excel spreadsheet (let’s call it “Excel 1”) And it contains large amount of info : item #, date, contact, po# , notes etc. weekly I add notes to this spreadsheet. Once a week I get new spreadsheet (excel 2) that has updated info. So some rows are added to excel 2 and some rows are removed because they’re resolved. I have to use excel 2 , BUT I need my notes from excel 1 added to excel 2 for the rows that are remaining same. So I need to use excel 2, I need to add notes from excel 1 for rows that are repeating. Currently, I do it with vlookup in excel. But Is there a way to create access database to have this done ?

    Just asking if it’s possible - to upload excel 1 today and keep adding notes in column “notes” , then , next Wednesday upload excel 2. By doing so:

    1) rows that are repeating in excel 2 should be updated with notes . Column “notes” in excel 2 will be empty, so copy notes from excel 1 to database.

    2) rows that do not appear in excel 2, should be removed. So some rows were in excel 1 but not excel 2 , delete them from database.

    3) new rows are added to excel 2, they didn’t exist in excel 1, add them to database.

    Thank you !!!!!!

  8. #8
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Marvelick, you should have started your own thread instead of hijacking. Could include a link to this existing thread if think it can be helpful to readers. New unanswered threads get more attention.

    Yes, Access is most likely better tool for your situation.
    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.

  9. #9
    Marvelick is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    2
    Thank you @June7, I apologize , I didn’t know I
    should do new thread I connected because I thought it’s similar situation. Thanks much for advice!

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

Similar Threads

  1. Merge Tables in Access Web App
    By dz227 in forum Macros
    Replies: 0
    Last Post: 01-17-2017, 12:57 PM
  2. Merge Tables
    By cfobare79 in forum Access
    Replies: 21
    Last Post: 05-02-2015, 03:53 PM
  3. Need to Merge 6 Similar Tables
    By CJS in forum Queries
    Replies: 6
    Last Post: 04-21-2015, 10:14 AM
  4. Don't know if I should merge tables (please help)
    By bigdaddy757 in forum Database Design
    Replies: 2
    Last Post: 05-30-2013, 01:52 PM
  5. How do I Merge Four Tables Together
    By SteveI in forum Queries
    Replies: 1
    Last Post: 03-04-2010, 10:53 AM

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