Sergey Samokhin <prikrutil(at)gmail(dot)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