mjanach mjanach - 1 year ago 83
SQL Question

SQL SELECT Aggregates from two unjoined tables

Is it possible to pull counts from two tables that are not joined?

For example:

SELECT
(SELECT COUNT(PERSON) FROM PEOPLE),
COUNT(BUILDINGS)
FROM
BUILDINGS


I get an error saying:


not a single-group group function.

Answer Source

One way to do it is by moving both count queries in the select clause:

select
  (SELECT COUNT(*) FROM PEOPLE) people_cnt,
  (SELECT COUNT(*) FROM BUILDINGS) building_cnt
from dual