views:

206

answers:

2

Hi!

I'm trying to run multiple queries on multiple tables- similar to "select count(*) from TableA where x=1" per table.

What I'd like to do, is get all of the count(*) values that are returned and sum them into a single value...

Any ideas?

+2  A: 
select sum(individual_counts) from
(
  select count(*) as individual_counts from TableA where x = 1
    union
  select count(*) from TableB where x = 2
....
) x

you normally only need the alias on the first select when using a union.

davek
This worked for me! Thanks! (original poster)
A: 

Not 100% sure what you mean, but maybe:

SELECT (SELECT COUNT(*) FROM tableA)+(SELECT COUNT(*) FROM tableB)
Andrew G. Johnson