Union Query Help Please

rede96

Registered User.
Local time
Today, 20:17
Joined
Apr 2, 2004
Messages
134
I have 2 tables with employee details in it. There is no natural link between the 2. I wish to write a query that will sum up the total pay for both tables.

I've had a look through the forum and it seems that a Union query is probably best.

I haven't worked with Unions before, so I did 2 sub queries to total the pay in both table and then union the 2 queries. I did this because there are some date parameters that I query each table by so I do this in the sub queries.

This works but I get 2 outputs in the result, the total pay from each table. I wanted to have just one output, which is the sum of all pay.

Can anyone help please.

SQL:
SELECT QrySub_TotalPay1.TotalPay 'sub query that sums up table 1
FROM QrySub_TotalPay1
UNION SELECT QrySub_TotalPay2.TotalPay 'sub query that sums up table 2
FROM QrySub_TotalPay2;

TIA.
 
why not use the union query in another query and sum the TotalPay
 
The simplest solutions are usually the best! :o

Thanks Dennisk.

It would be good to know if there was SQL that did what I wanted working directly with the tables. That way I could hard code the SQL behind a report button or something similar.

Anyway, thanks again.

Red
 
I would suggest Hard coding SQL in your code because you can always save the SQL as a query and call it from your code.
 

Users who are viewing this thread

Back
Top Bottom