Results 1 to 5 of 5
  1. #1
    guptaa13 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    2

    Union Query

    I have 5 tables in access 2010, 4 of them have data in them and I need to populate the 5th table with all data from the 4 tables. I know you have to create a Union query, but i dont know the sql statement

    Table 1 - data


    table 2 - data
    table 3 - data
    table 4 - data
    table 5 - combine data from table 1, table 2, table 3, table

    Any help would be very helpful

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Googled "access union query"
    Lots of returns. Here are two:
    http://office.microsoft.com/en-us/ac...010206109.aspx
    http://www.techonthenet.com/sql/union.php

    I do wonder if all of the tables have the same structure? Why copy data from 4 tables into a 5th?
    Kinda defeats the purpose of having a relational database...

  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,642
    As Steve asks, are the tables same structure? Is this a one-time event to get proper data structure? Will probably need another field in table 5 for a category value.

    Run 1 INSERT using UNION as source or run 4 INSERT actions.
    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
    guptaa13 is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    2
    All the fields are same in the table, but they are different sources, so I want to have one master table.

    All companies is the 5th table, and it has all the same fields as the other 4 tables

    I was trying the following statement and it is giving an error

    insert into [all_companies] SELECT 01_2013_CSMMI203.*
    FROM 01_2013_CSMMI203 UNION
    select 02_2013_CSMME107-002.*
    from 02_2013_CSMME107-002;

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,642
    Where did you build that sql? In query design view or in VBA?

    If you use the * wildcard, all fields must be in the same order in the table structure, otherwise enumerate the fields in each SELECT line. The first SELECT line sets the field names.

    Do you need a category value to be able to sort/filter the records?

    Build the UNION query object and save it. Then build an INSERT query object that uses the UNION as source. For some reason, forum is not letting me type UNION in the example query.

    SELECT *, 1 AS Category FROM 01_2013_CSMMI203
    ______ SELECT *, 2 FROM 02_2013_CSMME107-002
    ______ SELECT *, 3 FROM ...
    ______ SELECT *, 4 FROM ...;
    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.

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

Similar Threads

  1. Is a Union Query the way to go?
    By NISMOJim in forum Queries
    Replies: 2
    Last Post: 04-11-2014, 03:01 AM
  2. Replies: 8
    Last Post: 10-22-2012, 07:43 PM
  3. Union Query Help
    By pmp in forum Queries
    Replies: 4
    Last Post: 10-28-2011, 06:41 AM
  4. Union Query Help
    By jo15765 in forum Queries
    Replies: 7
    Last Post: 01-06-2011, 05:46 PM
  5. Please help me out with union query
    By radicrains in forum Access
    Replies: 1
    Last Post: 10-29-2010, 01:48 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