sybase sql - how to sum up UNION records

I like to sum up two sql results into one in one shot.

there are two tables, both has same columns but data records are different
I would like to see one line result as total sum value instead of two lines.
select
key,
sum(columnA)
from table A
group by key
UNION
select
key,
sum(columnA)
from table B
group by key

would you advise how this can be made...?
sleepinglukeAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jan FranekCommented:
If your version supports derived tables (ASE 12.5.1 and later):

select
key,
sum(columnA)
from (
select
key,
sum(columnA) as columnA
from table A
group by key
UNION
select
key,
sum(columnA)
from table B
group by key ) der_table
group by key
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jan FranekCommented:
If your version does not support derived tables use #temp table:

select
key,
sum(columnA) as columnA
into #temp
from table A
group by key

insert into #temp
select
key,
sum(columnA)
from table B
group by key

select
key,
sum(columnA)
from #temp
group by key
0
sleepinglukeAuthor Commented:
thank you very much it works!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Sybase Database

From novice to tech pro — start learning today.