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
JOIN with different tables
For a bit of completeness - this query will create a query to give you a count of all of the tables for a given owner.
The output is something like
Which you can then run to get your counts. It's just a handy script to have around sometimes.
SELECT (SELECT COUNT(*) FROM table1) + (SELECT COUNT(*) FROM table2) FROM dual;
A quick stab came up with:
Note: I tested this in SQL Server, so
From Dual
is not necessary (hence the discrepancy).My experience is with SQL Server, but could you do:
In SQL Server I get the result you are after.
select (select count() from tab1 where
field
like 'value') + (select count() from tab2 wherefield
like 'value') count