Click here to Skip to main content
15,920,633 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
SQL
select sum(Hocount) as total from handout where type= 'H' and course = 'AFF'


Output as follows

Total
150

SQL
select sum(seats) as total from stockentry where where type= 'H' and course = 'AFF'


Output as follows

Total
100


Using combining above two sql query i want the output as follows in single query.

Total
250

for that how can i write the sql query to get the output in single sql query.

Regards,
Narasiman P.
Posted
Updated 14-Jun-15 22:46pm
v2

Just an idea:

Try
SQL
select sum(Hocount) + sum(seats) as total 
from handout h
inner join stockentry s on h.type= s.type and h.course = s.course
where h.type= 'H' and h.course = 'AFF'
 
Share this answer
 
Try this
select sum(x.total) as Total from
(
select sum(Hocount) as total from handout where type= 'H' and course = 'AFF'
union
select sum(seats) as total from stockentry where where type= 'H' and course = 'AFF'
)x
 
Share this answer
 
Try:
SQL
SELECT (select sum(Hocount) as total from handout where type= 'H' and course = 'AFF') +
       (select sum(seats) as total from stockentry where where type= 'H' and course = 'AFF')
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900