Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to show two query results as one

Author  Topic 

dhani
Posting Yak Master

132 Posts

Posted - 2008-09-18 : 09:40:02
hello all

can any one please tell me how to do below way

i have 2 tables (ex table1, table2)


Query1:
select sum(col1) from table1



Query2:
select sum(col2) from table2


how can i show addition of above two queries (i.e., query1 result + query2 result)

thanks in advance
Dhani

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-18 : 09:50:23

select sum(summation) as summation from
(
select sum(col1) as summation from table1
union all
select sum(col2) from table2
) as t

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-18 : 09:51:47
or

select
(
select sum(col1) as summation from table1
)+
(
select sum(col2) from table2
)


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

dhani
Posting Yak Master

132 Posts

Posted - 2008-09-18 : 10:27:17

Madhivanan thank you very much
i got it

i appreciate, for your speedy answer

dhani
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-18 : 11:37:02
quote:
Originally posted by dhani


Madhivanan thank you very much
i got it

i appreciate, for your speedy answer

dhani



You are welcome

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -