Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dv0r6-0002XH-Os for pgsql-sql@arkaria.postgresql.org; Thu, 21 Sep 2017 12:45:24 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dv0r5-0001HC-I4 for pgsql-sql@arkaria.postgresql.org; Thu, 21 Sep 2017 12:45:23 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dv0r5-0001Gr-3P for pgsql-sql@postgresql.org; Thu, 21 Sep 2017 12:45:23 +0000 Received: from mta04.03.doruk.net.tr ([81.21.172.154] helo=mta04.doruk.net.tr) by makus.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dv0qv-0002ec-Ka for pgsql-sql@postgresql.org; Thu, 21 Sep 2017 12:45:21 +0000 Received: from cmail19.webkontrol.doruk.net.tr ([212.58.6.99]) by mta04.doruk.net.tr with esmtp (Exim 4.86) (envelope-from ) id 1dv0pu-0002kr-Ra for pgsql-sql@postgresql.org; Thu, 21 Sep 2017 15:44:10 +0300 Received: from DESKTOPM80CG12 ([83.66.158.235]) by cmail19.webkontrol.doruk.net.tr (IceWarp 11.1.2.0) with ASMTP id 201709211545383259 for ; Thu, 21 Sep 2017 15:45:38 +0300 From: =?iso-8859-9?B?RXJ0YW4gS/zn/Gtv8Gx1?= To: Subject: Single SQL to find if any record exists across several tables Date: Thu, 21 Sep 2017 15:45:02 +0300 Message-ID: <002301d332d7$745b1500$5d113f00$@1nar.com.tr> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-9" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AdMyvQs+fg0nElFxR3CJlU3sYAtG0w== Content-Language: tr List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hello, Using PostgreSQL 9.6.5 64bit running on Windows 10 64bit. There are no foreign key across tables in database. There is a table where company codes are kept. Most other tables includes company code value in a column. Column name is same for all tables which is "fk". Before deleting any company code row, I would like to be sure that it is not used in anywhere. Currently I am running a separate query for each table but that takes a lot of time and possibility to miss a table or two. 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 Thanks & regards, Ertan K=FC=E7=FCko=F0lu --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql