Results 1 to 12 of 12
  1. #1
    Efendak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    6

    How to join 5 tables with the same layout - use the query?

    Hello all,

    I have 5 tables with lot of data in each (over 100K rows). All 5 tables has the same fields. It is data for 5 different months. I would like to have all these data in 1 table. Could you please advice how to join them? Should I use some type of query?
    I am newie at Access...

    Thank you



    Regards,

    Marian

  2. #2
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Did you try use "UNION" or "UNION ALL"?
    UNION
    The UNION command is used to select related information from two tables, much like the JOIN command. However, when using the UNION command all selected columns need to be of the same data type. With UNION, only distinct values are selected.

    UNION ALL
    The UNION ALL command is equal to the UNION command, except that UNION ALL selects all values.

  3. #3
    Efendak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    6
    Thank you, it works when joining 2 tables. I used this code:
    SELECT July.*
    FROM July
    UNION ALL
    SELECT August.*
    FROM August;

    But what is I need to join 5 different tables? How to write the code please?

    Thank you

    Marian

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You just keep going:

    SELECT July.*
    FROM July
    UNION ALL
    SELECT August.*
    FROM August
    UNION ALL
    SELECT ...
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Efendak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    6
    Hello Phaldy,

    that is exactly what I did, even before sending my 2nd question. But after using:

    SELECT July.*
    FROM July
    UNION ALL
    SELECT August.*
    FROM August
    UNION ALL
    SELECT September.*
    FROM September;


    Access says: "Too many fields defined". What I do wrong please?

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Are you sure each table contains the exact same fields? You might try specifying, making sure to get them in the same order:

    SELECT Field1, Field2, Field3
    FROM July
    UNION ALL
    SELECT Field1, Field2, Field3
    FROM August
    UNION ALL
    SELECT Field1, Field2, Field3
    FROM September;
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Efendak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    6
    The structure of all tables is the same. But I found this: each my table includes 124 fields. This is probably too much for Access query, that is why it says "Too many fields defined". I tried to run the query with 85 fields only and it works. So probably some restriction within Access.

    Thank you guys for your help.

    Regards,

    Marian

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Oy, that's a lot of fields. Glad you found a solution. Are you normalizing the data into 1 table I hope?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Efendak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    6
    I am joining all months into 1 table to have option run queries over all months at one bout. Excel has difficulties to store so much data, so now I am learning Access. If I was an expert at Access, all my work would be done in a while and I could play chess instead :-)

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You will be happier with the data in one table. Welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    Run 5 INSERT SELECT queries to get the data combined into a single table.
    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.

  12. #12
    Efendak is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Dec 2014
    Posts
    6
    Finaly I used INSERT INTO Statement and that joined all 5 tables into 1. Thank you guys.

    Marian

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

Similar Threads

  1. Replies: 6
    Last Post: 11-19-2013, 01:38 AM
  2. Replies: 4
    Last Post: 02-12-2013, 12:54 PM
  3. Simepl query needed to JOIN three tables
    By mameha1977 in forum Queries
    Replies: 2
    Last Post: 10-19-2012, 06:00 AM
  4. inner join query with three tables.
    By fabiobarreto10 in forum Queries
    Replies: 2
    Last Post: 01-30-2012, 07:34 PM
  5. Join 4 Tables in 1 Query
    By sandlucky in forum Queries
    Replies: 5
    Last Post: 06-12-2011, 06:28 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