15,920,633 members
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

Solution 1

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'```

Solution 2

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```

Solution 3

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')```

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

Top Experts
Last 24hrsThis month
 k5054 85 OriginalGriff 70 Amarnath S 50 GamersLube LLC. 50 Rick York 45
 Pete O'Hanlon 920 OriginalGriff 801 Dave Kreskowiak 475 Richard MacCutchan 320 merano99 280

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