Sum of Two Union Queries

Hi I have the following union query that retrieves two counts. Can I
sum them up within this query, like wrap this in a sum function
somehow to get the total count? Or is there a better way to do this.
Please help. Using SQL 2000.



select count(user_id) from table1
UNION
select count(user_id) from table2

 

 

 

==========================================

 

If you want the latter, just the sum of the counts,
here is a possibility:

select
(select count(user_id) from table1)
+ (select count(user_id) from table2)
as totalCount

If you need to count user_id values only once when
they appear in both table1 and table2, you can do this:

select count(user_id)
from (
select user_id from table1
union
select user_id from table2
) T

你可能感兴趣的:(UNION)