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?
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?
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.
Not 100% sure what you mean, but maybe:
SELECT (SELECT COUNT(*) FROM tableA)+(SELECT COUNT(*) FROM tableB)