Re: sub-select parameter problem

From: Richard Huxton <dev(at)archonet(dot)com>
To: "Philippe Lang" <philippe(dot)lang(at)attiksystem(dot)ch>, <pgsql-sql(at)postgresql(dot)org>
Subject: Re: sub-select parameter problem
Date: 2004-03-04 11:51:21
Message-ID: 200403041151.21946.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christoph Haller 2004-03-04 12:53:18 Re: sub-select parameter problem
Previous Message Philippe Lang 2004-03-04 11:20:36 sub-select parameter problem