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

How to obtain sum from two tables. 1

Status
Not open for further replies.

rpk2006

Technical User
Apr 24, 2002
225
IN
Hi,

I have two tables with the same structure. Both tables have a field "Cost". I want that the sum total of "Cost" of on table and the sum total of "Cost" of the second table be added and stored in a variable. How to do that ?

Here is what I did, but it is not working...

Select sum(cost)+ sum(cost) as expr1 from Chemical, Glassware
There is always a new solution for the same problem.

Anonymous
 
Try:

Select sum(Chemical.cost)+ sum(Glassware.cost) as expr1
from Chemical, Glassware
 
I think DaveStL's query will give you the product of the sums from the two tables.

Here is a query that will give you a sum of the sums.

Code:
SELECT SUM(expr1) FROM
(
SELECT SUM( total_price ) AS expr1 FROM Chemical

UNION

SELECT SUM( total_price ) AS expr1 FROM Glassware
) anyOldAias
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top