X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 283D3D1B9A6 for ; Thu, 4 Mar 2004 11:52:03 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 36882-01 for ; Thu, 4 Mar 2004 07:51:47 -0400 (AST) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by svr1.postgresql.org (Postfix) with ESMTP id CDD26D1C9C2 for ; Thu, 4 Mar 2004 07:51:44 -0400 (AST) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-34.mail.demon.net with esmtp (Exim 3.35 #1) id 1AyrOD-00026K-0Y; Thu, 04 Mar 2004 11:51:47 +0000 Received: by mainbox.archonet.com (Postfix, from userid 529) id 7DACE162E1; Thu, 4 Mar 2004 11:51:38 +0000 (GMT) Received: from client17.archonet.com (client17.archonet.com [192.168.1.17]) by mainbox.archonet.com (Postfix) with ESMTP id A55091593F; Thu, 4 Mar 2004 11:51:36 +0000 (GMT) From: Richard Huxton To: "Philippe Lang" , Subject: Re: sub-select parameter problem Date: Thu, 4 Mar 2004 11:51:21 +0000 User-Agent: KMail/1.5 References: <6C0CF58A187DA5479245E0830AF84F42080222@poweredge.attiksystem.ch> In-Reply-To: <6C0CF58A187DA5479245E0830AF84F42080222@poweredge.attiksystem.ch> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <200403041151.21946.dev@archonet.com> X-Bogosity: No, tests=bogofilter, spamicity=0.000000, version=0.15.3 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/34 X-Sequence-Number: 17133 On Thursday 04 March 2004 11:20, Philippe Lang wrote: [working query] > It works fine. Excellent! :-) Oh - there's more :-( > Now, I need to do something else: the parameter of my sub-select is also > a member of the table I'm selecting. > > SELECT > > tableA.field1, > tableA.field2, > > tableB.field1, > tableB.field2, > > ( > SELECT tableB.field2 > FROM tableB > WHERE tableB.field1 = tableB.field1 (--> from-main-select?) - 1; > ) AS p > > FROM tableA > INNER JOIN tableB > ON tableA.pk = tableB.FK; > ------------------------------------------- > > How can I refer to the tableB.field1 parameter from the main query? I've > tried to do something like this, but without success: You're along the right lines, except I think you want to alias the table not the column. ... ( SELECT x.field2 FROM tableB AS x WHERE x.field1 = tableB.field1 - 1 ) ... HTH -- Richard Huxton Archonet Ltd