Re: [SQL] Single SQL to find if any record exists across several tables

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: [SQL] Single SQL to find if any record exists across several tables
Дата
Msg-id CAKFQuwbVLvU_wPCtQ35+2DyJjMrLmzrMKRuQF4JfRsKQkC8sTw@mail.gmail.com
обсуждение исходный текст
Ответ на [SQL] Single SQL to find if any record exists across several tables  (Ertan Küçükoğlu <ertan.kucukoglu@1nar.com.tr>)
Список pgsql-sql
On Thu, Sep 21, 2017 at 5:45 AM, Ertan Küçükoğlu <ertan.kucukoglu@1nar.com.tr> wrote:

Is it possible to build a single SQL statement and include all tables in it
so that I receive single "count(fk)" sum across all tables?

Several sample SQLs run at the moment are as follows:
Select count(fk) from cari
Select count(fk) from sipbaslik
Select count(fk) from stkdepo
Select count(fk) from stkkart
Select count(fk) from stkhar

​Without delving into dynamic SQL you can do either:

SELECT sum(count) FROM
(
SELECT count(fk) FROM can
UNION ALL
SELECT count(fk) FROM sipbaslik
)​ src

OR

SELECT 
(SELECT count(fk) FROM can)
+
(SELECT count(fk) FROM sipbaslik)

David J.

В списке pgsql-sql по дате отправления:

Предыдущее
От: Ertan Küçükoğlu
Дата:
Сообщение: [SQL] Single SQL to find if any record exists across several tables
Следующее
От: "Vishwanath M.C"
Дата:
Сообщение: [SQL] Not able to find the postgres version in stack builder