Skip site navigation (1) Skip section navigation (2)

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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Sergey Samokhin <prikrutil(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: Can't understand how a query from the documentation works
Date: 2009-09-08 19:40:11
Message-ID: 15529.1252438811@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-novice
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

In response to

Responses

pgsql-novice by date

Next:From: Michael WoodDate: 2009-09-08 22:47:26
Subject: Re: problem loading sql to database?
Previous:From: Sergey SamokhinDate: 2009-09-08 18:22:08
Subject: Can't understand how a query from the documentation works

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group