473,569 Members | 2,901 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Combining two tables with no duplicate names

I have 2 tables, Table 1 has Name, NameID, and A, B, C fields.
Table 2 has Name, NameID, and D, E fields.
Several of the Names/NameID are the same in both databases. I want my
merged the tables so each record looks like; Name, NameID, A, B, C, D,
E. I have merged them successfully but I am getting two records for
each name, one record for A, B, C fields, and another record for the
D, E fields.

Example,
Name NameID A B C D E
Smith, John 123 X X
Smith, John 123 X X

What I want to see is:

Name NameID A B C D E
Smith, John 123 X X X X

Thanks,

Don
Jun 27 '08 #1
2 3859
Don Barton wrote:
>I have 2 tables, Table 1 has Name, NameID, and A, B, C fields.
Table 2 has Name, NameID, and D, E fields.
Several of the Names/NameID are the same in both databases. I want my
merged the tables so each record looks like; Name, NameID, A, B, C, D,
E. I have merged them successfully but I am getting two records for
each name, one record for A, B, C fields, and another record for the
D, E fields.

Example,
Name NameID A B C D E
Smith, John 123 X X
Smith, John 123 X X

What I want to see is:

Name NameID A B C D E
Smith, John 123 X X X X

Looks like you used a simple UNION query to do the merge.

I think you might want a full outer join query something
like:

SELECT t1.Name, t1.NameID, t1.A, t1.B, t1.C, t2.D, t2.E
FROM [Table 1] As t1 LEFT JOIN [Table 2] As t2
ON t1.NameID = t2.NameID
UNION ALL
SELECT t2.Name, t2.NameID, Null, Null, Null, t2.D, t2.E
FROM [Table 2] As t2 LEFT JOIN [Table 1] As t1
ON t2.NameID = t1.NameID
WHERE t1.NameID Is Null

--
Marsh
Jun 27 '08 #2
Hi Marsh,
Thanks for the suggestion.
Bad news, good news:
Bad New:I tried the Union query, but still couldn't get it to work. .
Almost Good News: I next went in and checked both tables I wanted to
merge, and found that one of the tables had a duplicate name in it.
So I removed the duplicate, made a query that merged both tables (a
little different from the Union query, but did the same thing), and
the data looked great, BUT, when I attached query to a report, I was
still getting duplicates but only sporadically.
Good News: I had added a lookup table to the query that was suppose to
have unique locations, but there were some duplicates in the lookup
table, so this caused duplication in the report. I removed the
duplicates, now all is good.
I would have used the Union query, but I was having to do so much
cleaning up of the data, that I used the "long" way.

Thanks again for your help,

Don
>
Looks like you used a simple UNION query to do the merge.

I think you might want a full outer join query something
like:

SELECT t1.Name, t1.NameID, t1.A, t1.B, t1.C, t2.D, t2.E
FROM [Table 1] As t1 LEFT JOIN [Table 2] As t2
* * * * ON t1.NameID = t2.NameID
UNION ALL
SELECT t2.Name, t2.NameID, Null, Null, Null, t2.D, t2.E
FROM [Table 2] As t2 LEFT JOIN [Table 1] As t1
* * * * ON t2.NameID = t1.NameID
WHERE t1.NameID Is Null

--
Marsh- Hide quoted text -

- Show quoted text -
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
2967
by: Albretch | last post by:
.. Can you define the Character Set for particular tables instead of databases? . Which DBMSs would let you do that? . How do you store in a DBMS i18n'ed users' from input, coming over the web (basically from everywhere) store it and properly serve it back to users, . . .? . Can you point me to info on this? I would preferably use...
8
8342
by: Ilan | last post by:
Hi all I need to add data from two Excel sheets (both on the same workbook) to an existing table in my SQL DB. The problem is that each sheet holds different fields for the same record, though the records are sorted by row numbers. (I had to split the fields to different sheets because Excel has a limit of 256 fields in each sheet) My...
3
2773
by: Tome73 | last post by:
How can I easily add the rows of DataTable1 to the rows of DataTable2. Both queries are from the same table. I can always use the column names with myRow, but I was wishing for a shortcut. When I try this it doesn’t work. for (int i = 0; i < dataTable1.Rows.Count; i++) { myRow = dataTable2.NewRow(); myRow = dataTable1.Rows;...
4
11528
by: Tony Williams | last post by:
I want to combine two tables into one. I have a table with all the field definitions from two other tables. I now need to update this new table with the data from the other two tables.However both the existing tables have 2 fields that are common ie txtmonthlabel and txtcompany. I tried running an append query from each table but I got...
1
10590
by: Brian | last post by:
I'm trying to find a way to search multiple tables for the same record. Say I have 3 tables all with a name column, I need to search all 3 tables and find matching names. Is there an easy way to accomplish this?
1
1408
by: Reidar Jorgensen | last post by:
I have several databases, identical in structure but with different data. Is there an esay way to combine all the data into one big database? There are six tables.
2
1567
by: m.k.ball | last post by:
Hi - I have some tables designed to keep track of order. The main table contains a session id, address and date. Linked to this I have a table of items that make up each order. I'm concerned that over the course of a few weeks performance will slow down as the tables fill up, so I though I would make duplicates of each table and have any...
2
3804
by: farouqdin | last post by:
Hi all i have code which loops through table and deletes the duplicate records. This code does it for one table. How do i change it so it goes through several tables? On Error Resume Next Dim db As DAO.Database, rst As DAO.Recordset Dim strDupName As String, strSaveName As String Set db = CurrentDb()
2
3083
by: Haas C | last post by:
Hi all, I am a newbie who goes through tasks in apainfully slow and in an inefficient way in Access. I've been experimenting here and there and have figured out a few things, but for the most part, I still need help. Here's a quick question that can help me get rolling with a new project. I have multiple tables, all have the same field...
0
7693
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7605
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8118
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6277
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5501
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5217
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3631
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2105
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.