Results 1 to 15 of 15
  1. #1
    aemara is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    23

    merging 2 tables that have identical fields except one table has an extra column for a primary key

    Hi guys,



    I have 2 tables with fields that look like this:

    Table1: ID name age gender (where ID is the primary key) Table2: name age gender


    These tables have thousands of rows. Now I am trying add the info in table2 to table1. Table2 has the age and gender fields filled up while the name field is empty. I thought adding the name field would help with the merging.

    I tried using a union query, but the result was a merged table with no ID field.
    Could someone help point me in the right direction? I would very much appreciate that.

    aemara

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    How does table 2 relate to table1? If table 2 name field is empty, what is the point of merging the two tables?

    BTW, storing the age is not a good idea. Every year people age. It is better to store the birth date and calculate the age.


    And welcome to the Access forums..

  3. #3
    aemara is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    23
    Thank you for your reply and your welcoming ssanfu,

    Well both tables have their age and gender fields filled. I want to add these ages and genders from table2 into table1 even if it would mean that some of the fields in the resulting table will be empty for those records ( they will be filled later on).

    You're right I should be using birth date :P thanks

    Sorry for the late reply

    Ahmed

  4. #4
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    So how do you know which record in table 2 is related to which record in table 1?

    Table1: ID name age gender (where ID is the primary key)
    Table2: name age gender
    It looks like the only common field is the name field.
    You can try using an update query, but the problem is if there are two records with the same name, how will you know which record would/should be updated?

    BTW, "Name" is a reserved word in Access and shouldn't be used for object names.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I am equally confused. Of what value are records with only age and gender data? Therefore a UNION is meaningless.

    Agree with Steve about updating based on name link. Names are very poor unique identifiers. And if the name field is empty, there is no data to join on anyway.
    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.

  6. #6
    aemara is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    23
    The tables are not related, and for simplicity I removed the 'name' field from table 2. All I was trying to do was add the ages and genders to table 1, even if that left ID and name in table 1 empty.
    I looked more online and I found that an append query might do the trick, but so far everytime I fill in the details for the append query and view it in datasheet view, it doesn't show me the appended data.

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Did you RUN the append query?
    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.

  8. #8
    aemara is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    23
    Shouldn't I wait until the datasheet view shows me the correct info? I could probably run it on a copy just in case it messes up my tables

  9. #9
    aemara is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    23
    Ok so I ran it and it seems to work, but I don't understand why. I mean whats the point of checking different views of the query before running it, if checking it doesnt show you the correct results?

  10. #10
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I'm not sure of the answer. I haven't looked at an append query object in so long, don't remember.

    How many records were involved? Maybe a copy/paste would have served.
    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.

  11. #11
    aemara is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    23
    We're talking hundreds of thousands..I tried copy pasting but there was a problem with file sharing lock count being exceeded

  12. #12
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    I just tested an INSERT SELECT query written in SQL view and in datasheet view I do see records. However, trying to build APPEND query to pull data from a table with the design view is just frustrating. I don't have any databases that use saved action query objects (DELETE, INSERT, UPDATE). I do all action SQLs in VBA.
    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.

  13. #13
    aemara is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    23
    What exactly is VBA? From what Ive read online I'm not sure what it is

  14. #14
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Visual Basic for Applications - VBA.

    It is programming language packaged with Microsoft Office applications. http://office.microsoft.com/en-us/ac...010341717.aspx
    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.

  15. #15
    aemara is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    23
    Thanks for the link! I might actually need this.

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

Similar Threads

  1. Search Multiple Tables (Identical Fields)
    By tristangemus in forum Queries
    Replies: 1
    Last Post: 06-21-2013, 10:32 AM
  2. Replies: 3
    Last Post: 04-05-2013, 10:40 PM
  3. Replies: 5
    Last Post: 08-05-2011, 12:33 PM
  4. Replies: 3
    Last Post: 12-10-2009, 02:16 PM
  5. One table multiple fields identical properties.
    By swampdonkey in forum Queries
    Replies: 2
    Last Post: 09-29-2006, 10:53 AM

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