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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Union Query that adds payments

Status
Not open for further replies.

TJVFree

Technical User
Nov 22, 2010
236
US
Hi,
I'm now to using Union query’s and would like to sum my payments in the query below.

SELECT [PayrollNo],[Name], [payment]
FROM [Table1]

UNION SELECT [PayrollNo],[Name], [payment]
FROM [Table2]

Thank you for your help

TCB
 
I would try something like:

Code:
[blue]Select PayrollNo, MyName, SUM(MyPayement) As PaySum
From ([/blue]
SELECT [PayrollNo],[Name], [payment]
FROM [Table1]
UNION 
SELECT [PayrollNo],[Name], [payment]
FROM [Table2][blue]
) Group By PayrollNo, MyName[/blue]

BTW - 'Name' is a bad name for a field.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
Like this ?
SELECT PayrollNo,[Name],Sum(payment) AS Total
FROM (SELECT [PayrollNo],[Name], [payment] FROM [Table1]
UNION SELECT [PayrollNo],[Name], [payment] FROM [Table2]) U
GROUP BY PayrollNo,[Name]


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks Andrzejek and PHV. I was able to get it to work with your help

TCB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top