Reputation: 359
I've set this sql query on a heroku database "clip" (postgresql)
select count(table1) as colname1, count(table2) as colname2 from table1, table2;
Each table has 2 rows, and the solution of the count is 4 in each column value.
--------------------
colname1 | colname2
4 | 4
--------------------
What am I missing either on sql basics or DB specific?
Upvotes: 0
Views: 65
Reputation: 536
This should give you what you are looking for.
select cnt1, cnt2
from ( select count(1) cnt1 from table1) a,
( select count(1) cnt2 from table2) b;
Upvotes: 2
Reputation: 17906
you are making a cross join, so it is counting the row count of table 1 multiplied by the row count of table 2.
Upvotes: 2