pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: selva kumar <selva.logic@hotmail.com>
Cc: pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org>
Subject: Re: Query will execute when inner query have issue
Date: Thu, 23 Jan 2020 09:43:33 -0500
Message-ID: <5259.1579790613@sss.pgh.pa.us> (raw)
In-Reply-To: <MAXPR01MB21574B7FDC100157148384EEE20F0@MAXPR01MB2157.INDPRD01.PROD.OUTLOOK.COM>
References: <MAXPR01MB21574B7FDC100157148384EEE20F0@MAXPR01MB2157.INDPRD01.PROD.OUTLOOK.COM>

selva kumar <selva.logic@hotmail.com> 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





view thread (6+ messages)  latest in thread

Message-ID: <5259.1579790613@sss.pgh.pa.us>
Permalink:  ../5259.1579790613@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/5259.1579790613@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, selva.logic@hotmail.com
  Subject: Re: Query will execute when inner query have issue
  In-Reply-To: <5259.1579790613@sss.pgh.pa.us>
  References: <MAXPR01MB21574B7FDC100157148384EEE20F0@MAXPR01MB2157.INDPRD01.PROD.OUTLOOK.COM> <5259.1579790613@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox