Join Two Tables?

Big Monkey

Active Member
Joined
Nov 5, 2005
Messages
255
I have two tables which are updated daily. There is a unique ID that can be found on both tables, but there isn't always a record for that same ID on both tables every day.

I need a query or to make a new table that will join the fields from both tables for each unique ID, even if the ID is missing from one table (leave that field null/blank)

Table1

03/11/09..Person2..Field_1
03/12/09..Person3..Field_1
03/13/09..Person4..Field_1

Table2

03/10/09..Person1..Field_2
03/12/09..Person3..Field_2
03/13/09..Person4..Field_2

I want the end result to be:

Table/Query

03/10/09..Person1..Field_1..Field_2
03/11/09..Person2..Field_1..Field_2
03/12/09..Person3..Field_1..Field_2
03/13/09..Person4..Field_1..Field_2


Hope that's clear enough. Any help?
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Big Monkey,

Since the missing value can come from either table, you cannot use a standard join.

Try something like this:
Code:
SELECT Date, Person, Max(Field1) AS MaxOfField1, Max(Field2) AS MaxOfField2
FROM (SELECT Table1.Date, Table1.Person, Table1.Field1, "" AS Field2
FROM Table1
UNION SELECT Table2.Date, Table2.Person, "" AS Field1, Table2.Field2 
FROM Table2)
GROUP BY Date, Person;
It uses a sub query to union the values together with empty strings as the opposite field. Then it groups the resultant data by date and person, showing the max from the fields. As long as you only expect one value per day per person from either table, this should work. Good luck. - Bob
You may want to change the resultant field names.
 
Upvote 0

Forum statistics

Threads
1,214,947
Messages
6,122,413
Members
449,082
Latest member
tish101

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top