Solved

How to combine multiple tables in Access 2010 into single table

Posted on 2014-09-03
7
8,424 Views
Last Modified: 2014-09-12
Hello,

I have 7 tables of information, all tables have the same fields.  I would like to combine the tables into 1 master table and then remove the previous ones.  My intent to do this is so I then have just one table to work with in trying to isolate and remove duplication.  Any and all assistance would be greatly appreciated.
0
Comment
Question by:FreddyBass
7 Comments
 
LVL 37

Expert Comment

by:Neil Russell
ID: 40301936
INSERT INTO maintablename SELECT * FROM firstoldtable
INSERT INTO maintablename SELECT * FROM secondoldtable
INSERT INTO maintablename SELECT * FROM nextoldtable

etc...
0
 

Author Comment

by:FreddyBass
ID: 40301982
Hi Neilsr,

Thank you for your input, where to put what you have written?

INSERT INTO maintablename SELECT * FROM firstoldtable
INSERT INTO maintablename SELECT * FROM secondoldtable
INSERT INTO maintablename SELECT * FROM nextoldtable
0
 
LVL 37

Accepted Solution

by:
Neil Russell earned 500 total points
ID: 40301990
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 30

Expert Comment

by:hnasr
ID: 40302004
Try:

SELECT * INTO mainTable
FROM (SELECT * FROM tbl1 UNION  SELECT * FROM tbl2 ...  UNION SELECT * FROM tbl7)

... to be replaced by UNION for all other remaining tables
0
 

Author Comment

by:FreddyBass
ID: 40302013
Hello Neilsr,

I will have a look at the following link and let you know if that provides the solution I am looking for.

Thank you

Fred
0
 
LVL 31

Expert Comment

by:Helen_Feddema
ID: 40303643
It might be better to do this operation in VBA code.  If each table has an ID field as the key field, you won't be able to append to that field.  Also, you may need to check for duplicates before adding a record.  In some cases it might be more appropriate to update an existing record rather than adding a new one.  here is some typical code for an "append or update" choice:
      strSearch = "[Code] = " & lngCode
      Debug.Print "Search string: " & strSearch
      rstTarget.FindFirst strSearch
      
      If rstTarget.NoMatch = True Then
         'Add new record
         rstTarget.AddNew
         rstTarget![Code] = lngCode
         rstTarget![TechName] = strTech
         rstTarget![WorkDate] = dteWork
         rstTarget![StartTime1] = rstSource![StartTime]
         rstTarget![EndTime1] = rstSource![EndTime]
         curRate = CCur(Nz(rstSource![Rate]))
         rstTarget![Rate] = curRate
         rstTarget.Update
      Else
         'Update existing record
         rstTarget.Edit
         rstTarget![StartTime2] = rstSource![StartTime]
         rstTarget![EndTime2] = rstSource![EndTime]
         rstTarget.Update
      End If

Open in new window

0
 

Author Closing Comment

by:FreddyBass
ID: 40319945
Thank you for providing me the link, I was able to find more information there for what I am trying to do
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question