Re: Problem using Subselect results

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: oheinz(at)stud(dot)fbi(dot)fh-darmstadt(dot)de
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Problem using Subselect results
Date: 2003-07-28 16:41:29
Message-ID: 20030728164129.GA25693@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Wed, Jul 23, 2003 at 14:51:48 +0200,
oheinz(at)stud(dot)fbi(dot)fh-darmstadt(dot)de wrote:
> I want to use the result of a subselect as condition of another one.

The two selects you use ar both from items at the same level and hence can't
reference one another. In your example below you could just use a join.

> CREATE VIEW my_view AS SELECT b,c
> (SELECT a, b FROM table2 WHERE b=1) my_ab,
> (SELECT c FROM table3, my_ab WHERE table3.a=my_ab.a) my_c;

Something like:

CREATE VIEW my_view AS
SELECT table2.b, table3.c
from table2, table3
where
table2.b = 1 and
table2.a = table3.a;

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Dmitry Tkach 2003-07-28 16:43:43 Re: Very strange 'now' behaviour in nested triggers.
Previous Message Tom Lane 2003-07-28 05:45:54 Re: Using a compound primary key