Results 1 to 7 of 7
  1. #1
    CJS is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    2

    Need to Merge 6 Similar Tables

    Hi Everyone,



    I am new to Access and need assistance with a Query.

    I have 6 tables.

    TABLE 1: Customer Number, Customer Name, Vendor Number, Vendor Name, Fiscal Year, Sales
    TABLE 2: Customer Number, Customer Name, Vendor Number, Vendor Name, Fiscal Year, Sales
    TABLE 3: Customer Number, Customer Name, Vendor Number, Vendor Name, Fiscal Year, Sales
    TABLE 4: Customer Number, Customer Name, Vendor Number, Vendor Name, Fiscal Year, Sales
    TABLE 5: Customer Number, Customer Name, Vendor Number, Vendor Name, Fiscal Year, Sales
    TABLE 6: Customer Number, Customer Name, Vendor Number, Vendor Name, Fiscal Year, Sales

    Each table contain approximately 1 million rows.
    Table 1 contains all sales data from 2009 (fiscal year is 2009 for each row), table 2 contains sales data from 2010 (fiscal year is 2010 for each row), table 3 contains sales data from 2011 (fiscal year is 2011 for each row),table 4 contains sales data from 2012 (fiscal year is 2012 for each row), table 5 contains sales data from 2013 (fiscal year is 2013 for each row), table 6 contains sales data from 2014 (fiscal year is 2014 for each row)

    I want to essentially create 1 table...
    Customer Number, Customer Name, Vendor Number, Vendor Name, 2009 Sales,2010 Sales, 2011 Sales, 2012 Sales,2013 Sales, 2014 Sales

    How do I make this happen???

    I am familiar with the iif function and establishing relationships. I can't seem to get what I want though... Any assistance would be appreciated!

  2. #2
    JeffChr is offline Advanced Beginner
    Windows 7 64bit Access 2010 32bit
    Join Date
    Feb 2014
    Posts
    82
    you need to run append queries to a pre-designed table containing the fields you mentioned above for your "1 table". Create a table, and then design and run 6 different append queries. The only difference between the append queries will be the destination for the Sales field.

  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,770
    That resulting table is not a normalized structure. Should be one field with sales data and another field with the year.

    Customer info should not be duplicated. Should be a Customers table and then save only CustomerID into the Sales table.

    A UNION query can replicate the combined table structure.

    SELECT [Customer Number], [Customer Name], [Vendor Number], [Vendor Name], [Fiscal Year], Sales FROM Table1
    UNION SELECT [Customer Number], [Customer Name], [Vendor Number], [Vendor Name], [Fiscal Year], Sales FROM Table2
    UNION SELECT [Customer Number], [Customer Name], [Vendor Number], [Vendor Name], [Fiscal Year], Sales FROM Table3
    UNION SELECT [Customer Number], [Customer Name], [Vendor Number], [Vendor Name], [Fiscal Year], Sales FROM Table4
    UNION SELECT [Customer Number], [Customer Name], [Vendor Number], [Vendor Name], [Fiscal Year], Sales FROM Table5
    UNION SELECT [Customer Number], [Customer Name], [Vendor Number], [Vendor Name], [Fiscal Year], Sales FROM Table6;

    There is no wizard or builder for UNION query, must type in SQL view of query designer.

    Use that query in other queries or as source to populate combined table.
    Last edited by June7; 04-21-2015 at 10:15 AM.
    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
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,929
    Not sure if creating a new table or using a union query, which would be quicker, but to follow on having got your one table (Jeffchr) or unionised view (June7) with 6 million rows, use a crosstab query to create the view you want. I would also suggest that it would be more efficient if this table/union query does not contain the customer name and vendor name. Instead, create another table for each of these to contain customer number and customer name - use a select distinct in your update query to avoid duplicates and have a primary key on customer number to avoid adding the same customer more than once from each of your original tables. You can then link back to these for the name.

  5. #5
    CJS is offline Novice
    Windows 7 32bit Access 2010 32bit
    Join Date
    Apr 2015
    Posts
    2
    Ultimately I'm trying to get my larger all-encompassing table created so that I can export the whole thing into a Pivot Table in Excel.

    JeffChr: Append Query suggestion leads to an Error Statement. Thank You for the suggestion.
    June7: Not familiar with SQL so the UNION Query is likely beyond my skill set. Appreciate the insight and it's good to know the logic based behind that method.
    Ajax: Unfortunately since I'm trying to get this over into excel ultimately, your suggestion, although likely a great option for most in the access world, it doesn't meet my final application.

    I really appreciate all you taking the time to assist!

  6. #6
    CJ_London is online now VIP
    Windows 8 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,929
    good luck with your project

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    What is exact error message? Post the append query sql statement for analysis.

    Did you try opening query designer in SQL View and copy/paste the UNION query? Replace with actual table names.

    Why Excel pivot table? Access 2010 has pivot view of tables and forms.
    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. Replies: 3
    Last Post: 03-18-2015, 09:24 AM
  2. Find similar names in two tables
    By Ruegen in forum Queries
    Replies: 1
    Last Post: 08-17-2014, 07:25 PM
  3. Replies: 7
    Last Post: 06-09-2014, 11:55 AM
  4. Finding similar names between two tables.
    By Laurie B. in forum Access
    Replies: 1
    Last Post: 07-15-2011, 03:21 PM
  5. Replies: 4
    Last Post: 04-13-2011, 10:11 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