Reputation: 807
How can I select count(*) from two different tables (table1 and table2) having as result:
Count_1 Count_2
123 456
I've tried this:
select count(*) as Count_1 from table1
UNION select count(*) as Count_2 from table2;
But here's what I get:
Count_1
123
456
I can see a solution for Oracle and SQL server here, but either syntax doesn't work for MS Access (I am using Access 2013). Select count(*) from multiple tables
I would prefer to do this using SQL (because I am developing my query dynamically within VBA).
Upvotes: 0
Views: 3850
Reputation: 97101
Cross join two subqueries which return the separate counts:
SELECT sub1.Count_1, sub2.Count_2
FROM
(SELECT Count(*) AS Count_1 FROM table1) AS sub1,
(SELECT Count(*) AS Count_2 FROM table2) AS sub2;
Upvotes: 4
Reputation: 6477
Select TOP 1
(Select count(*) as Count from table1) as count_1,
(select count(*) as Count from table2) as count_2
From table1
Upvotes: 3
Reputation: 2159
Is a SUM (or AVG) like this what you are trying to achieve?
select sum(count) from (
select count(*) as Count from table1
UNION select count(*) as Count from table2
);
Upvotes: 0