union? [message #10207] |
Thu, 08 January 2004 11:58 |
Pam
Messages: 20 Registered: October 2000
|
Junior Member |
|
|
Is it possible to use 'union', to pull information from 2 tables, then sum an amount field for the combination of the two? For example:
table1
1 15.00
2 20.00
table2
1 35.00
2 30.00
result
1 50.00
2 50.00
My question might be, can you use 'group by/sum' for the overall results when querying 2 tables?
|
|
|
Re: union? [message #10208 is a reply to message #10207] |
Thu, 08 January 2004 12:11 |
Todd Barry
Messages: 4819 Registered: August 2001
|
Senior Member |
|
|
Sure, just use an inline view, but be sure to use UNION ALL instead of UNION.
select id, sum(amount)
from (select id, amount
from t1
union all
select id, amount
from t2)
group by id;
|
|
|