Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dTChY-0005qE-Jh for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2017 19:44:36 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dTChX-0006uL-H2 for pgsql-sql@arkaria.postgresql.org; Thu, 06 Jul 2017 19:44:35 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dTCgY-00057c-BG for pgsql-sql@postgresql.org; Thu, 06 Jul 2017 19:43:34 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dTCgQ-0005sa-Ru for pgsql-sql@postgresql.org; Thu, 06 Jul 2017 19:43:33 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id v66JhNEi026803; Thu, 6 Jul 2017 15:43:23 -0400 From: Tom Lane To: Ed Rouse cc: "pgsql-sql@postgresql.org" Subject: Re: Finding the negative In-reply-to: References: Comments: In-reply-to Ed Rouse message dated "Thu, 06 Jul 2017 19:13:09 -0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <26801.1499370203.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 06 Jul 2017 15:43:23 -0400 Message-ID: <26802.1499370203@sss.pgh.pa.us> 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 Ed Rouse writes: > ... What I need is to find the ones NOT in either table. I have tried usi= ng not in both with or/and and various parenthesis. I tried: > select count(distinct(loid)) from pg_largeobject where not ((loid in (sel= ect content from attachments) or loid in (select content from idw_form_work= flow_attachments))); > This should work since, if the loid is not in the content of either table= , it should be F or F =3D F, negated to T; > which I would think would then count, but I get back 0 instead of the rat= her large number I should get. I'm suspicious that this means there's at least one NULL in those content columns. That will cause the IN check to return either TRUE or NULL, not FALSE. You could recast to use EXISTS, or explicitly exclude nulls while selecting from the attachments tables. regards, tom lane --=20 Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql