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
Other slightly different methods:
Here is from me to share
Option 1 - counting from same domain from different table
Option 2 - counting from different domain for same table
Option 3 - counting from different domain for same table with "union all" to have rows of count
Enjoy the SQL, I always do :)
Just because it's slightly different:
It gives the answers transposed (one row per table instead of one column), otherwise I don't think it's much different. I think performance-wise they should be equivalent.
As additional information, to accomplish same thing in SQL Server, you just need to remove the "FROM dual" part of the query.