Multiple Table problem

coyotem78

New Member
Joined
Sep 9, 2002
Messages
44
Hiya

I have problem hopefully someone can solve.

Lets say I have 2 tables. Each table contains user data. Let say, the 2 tables represent 2 months. In each month we may have the same users and some new users. An example:

Table 1

UserA1 16/10/1989 25
UserG 25/08/1957 3
UserA2 30/05/1985 8

Table 2

UserA1 16/10/1989 16
UserB 16/10/1989 8
UserG 25/08/1957 2

where the 2nd col is the Date of Birth, 3rd col is some data. In addition UserA1 and UserA2 have the same name, but different people.

Now what I want to do is to display all the users and sum the data like this

UserA1 16/10/1989 41
UserB 16/10/1989 8
UserG 25/08/1957 5
UserA2 30/05/1985 8

Obviously I have to use a query of some kind but don't know how to do it, prolly be very simple.

Thanks in advance

coyotem78
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi,

You can do this by using a union query and then by aggregating your data. You can either do this using 2 queries (1 for the union, 1 for the aggregration based on the first) or you can do it all in one hit. Here's how to do the latter:-

This example assumes your field names are Field1, Field2 and Field3 and your tables are named Table1 and Table2. You'll need to change to match your tables' field names.<pre>SELECT SubQry.Field1,SubQry.Field2, Sum(SubQry.Field3) AS TotalField3 FROM
(SELECT * FROM Table1 UNION ALL SELECT * FROM Table2) AS SubQry
GROUP BY SubQry.Field1, SubQry.Field2;</pre>

What this is doing is using a nested query. The nested union query is executed first, then the outer query is executed. Let me know if you can't get it to work.

_________________
<font face="Arial Black" color="#0000FF">Hope this helps,
DK</font>

This message was edited by dk on 2003-02-20 06:36
 
Upvote 0
There are actually too many fields to mention but to make things simple cut it to 4: Letters of Name; Date of Birth; Agency ID; Transport - total (one way trips)

Table names: Extract 2001-3; Extract 2001-4
 
Upvote 0

Forum statistics

Threads
1,221,493
Messages
6,160,139
Members
451,624
Latest member
TheWes

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