mjanach mjanach - 6 months ago 25
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

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