Re: Can't understand how a query from the documentation works

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Can't understand how a query from the documentation works
Дата
Msg-id 15529.1252438811@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Can't understand how a query from the documentation works  (Sergey Samokhin <prikrutil@gmail.com>)
Ответы Re: Can't understand how a query from the documentation works  (Sergey Samokhin <prikrutil@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Sergey Samokhin
Дата:
Сообщение: Can't understand how a query from the documentation works
Следующее
От: Michael Wood
Дата:
Сообщение: Re: problem loading sql to database?