Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iudhx-0007zR-BF for pgsql-bugs@arkaria.postgresql.org; Thu, 23 Jan 2020 14:43:45 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1iudhv-0007i0-48 for pgsql-bugs@arkaria.postgresql.org; Thu, 23 Jan 2020 14:43:43 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1iudhu-0007ht-NJ for pgsql-bugs@lists.postgresql.org; Thu, 23 Jan 2020 14:43:42 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iudhr-0003Qz-7T for pgsql-bugs@lists.postgresql.org; Thu, 23 Jan 2020 14:43:41 +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 00NEhXxs005260; Thu, 23 Jan 2020 09:43:33 -0500 From: Tom Lane To: selva kumar cc: "pgsql-bugs@lists.postgresql.org" Subject: Re: Query will execute when inner query have issue In-reply-to: References: Comments: In-reply-to selva kumar message dated "Thu, 23 Jan 2020 07:34:40 +0000" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <5258.1579790613.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Thu, 23 Jan 2020 09:43:33 -0500 Message-ID: <5259.1579790613@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk selva kumar writes: > We tried query in a following manner. > SELECT * FROM A where A.id IN (SELECT B.id from B); > In the above query Table B does not have id. But this query return all A= table records You sure that's *actually* what you wrote? The usual mistake is to fail to qualify the inner query's column reference at all: SELECT * FROM A where A.id IN (SELECT id from B); If B has no "id" column, it's still a legal SQL query, interpreted as SELECT * FROM A where A.id IN (SELECT A.id from B); so as long as B has any rows, the IN-test succeeds for every non-null value of A.id. People get burned by that all the time, but it's acting as required by the SQL standard. regards, tom lane