Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Merge two different layout Databases

Status
Not open for further replies.

tjc240e

Technical User
Nov 12, 2004
133
US
What I want to do is Merge two tables based on an Id Number. All my families are assigned a number. I have two seperate tables and I know that some people exist in the table 2 that do not in table 1. The main problem is that table 2 does not have the same fields as table 1.

Table 1 has id number, last name, first name, middle name, street addr, city, state, zip
Table 2 has id number, full name, full address

Can anyone think of a simple way of merging these two tables together? Or maybe even a complex way of doing it. :)

Thanks
 
In order to match records from two tables, there must be a common field. You mentioned an ID. If the ID exists in both tables, then you can use a JOIN. You would get a merged table that contains all the fields from both source tables.

Here's the general syntax:

SELECT TABLE1.*, TABLE2.* FROM TABLE1 FULL OUTER JOIN TABLE2 ON TABLE1.IDFIELD=TABLE2.IDFIELD

The purpose of 'FULL OUTER' is to include records from either table that don't have matching records in the other table.

Mike Krausnick
Dublin, California
 
I omitted a caveat in my prior post. My suggestion assumes that each source table contain no more than one matching record in the other table. If the relationship is more like a parent-child, for example where there are many records in TABLE2 that match the same record in TABLE1, then your merged tables will contain records with duplicate IDs.

Also, if you use the example and don't specify the fields explicitly, you will have duplicate occurances of all fields that exist in both your source tables. For example if you have a LASTNAME field in both source tables, the merged table will contain two fields: LASTNAME_A and LASTNAME_B. You can avoid this by specifying in the SELECT which fields you want from which source tables.




Mike Krausnick
Dublin, California
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top