How can I select count(*)
from two different tables (call them tab1
and tab2
) having as result:
Count_1 Count_2
123 456
I've tried this:
select count(*) Count_1 from schema.tab1 union all select count(*) Count_2 from schema.tab2
But all I have is:
Count_1
123
456
As I can't see any other answer bring this up.
If you don't like sub-queries and have primary keys in each table you can do this:
But performance wise I believe that Quassnoi's solution is better, and the one I would use.
If the tables (or at least a key column) are of the same type just make the union first and then count.
Or take your satement and put another sum() around it.
or