Lieven Cardoen
Lieven Cardoen

Reputation: 25959

Join two counts in sql query

Is it possible to have the sum of next two queries in one query?

select COUNT(1) 
from BinaryAssets.BinaryAssetsTags
where TagId = 1731

select COUNT(1) 
from Planning.ScheduleTag
where TagId = 1731

Result from first query is 3 for example, from the second 2. I want one query that gives me back 5.

Upvotes: 0

Views: 726

Answers (2)

zerkms
zerkms

Reputation: 254926

SELECT 
(select COUNT(1) from BinaryAssets.BinaryAssetsTags where TagId = 1731) 
+ 
(select COUNT(1) from Planning.ScheduleTag where TagId = 1731) 
AS total_sum

Upvotes: 6

You can follow this syntax ,

select (select Count(1) from a)+(select Count(1) from b) as 'Total Count'

Upvotes: 2

Related Questions