Re: Can't understand how a query from the documentation works - Mailing list pgsql-novice

From Tom Lane
Subject Re: Can't understand how a query from the documentation works
Date
Msg-id 15529.1252438811@sss.pgh.pa.us
Whole thread Raw
In response to Can't understand how a query from the documentation works  (Sergey Samokhin <prikrutil@gmail.com>)
Responses Re: Can't understand how a query from the documentation works  (Sergey Samokhin <prikrutil@gmail.com>)
List pgsql-novice
Sergey Samokhin <prikrutil@gmail.com> writes:
> The query I have a problem with is:

> SELECT * FROM fdt WHERE c1 IN (SELECT c1 FROM t2 WHERE c2 = fdt.c1 + 10);

> I've never seen column names being used inside subquries, so let me
> explain how I supposed it to work. It should help you to see where I'm
> making a mistake.

I think you're misunderstanding the behavior of the "outer reference"
fdt.c1.  What will happen (at least conceptually) is that for each row
of fdt, the whole sub-SELECT will be evaluated using that row's value
of fdt.c1, producing a list of t2.c1 values.  Then, if the fdt row's
value of c1 appears in that list, the fdt row will be included in the
result.

            regards, tom lane

pgsql-novice by date:

Previous
From: Sergey Samokhin
Date:
Subject: Can't understand how a query from the documentation works
Next
From: Michael Wood
Date:
Subject: Re: problem loading sql to database?