X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4B60CD1C4E1 for ; Thu, 24 Jul 2003 12:11:19 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 35092-02 for ; Thu, 24 Jul 2003 09:10:37 -0300 (ADT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id 7EA7ED1C4DA for ; Thu, 24 Jul 2003 09:11:15 -0300 (ADT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Thu Jul 24 14:11:16 2003 +0200 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id OAA14537; Thu, 24 Jul 2003 14:11:15 +0200 (METDST) Message-ID: <3F1FCCE2.47ACF401@rodos.fzk.de> Date: Thu, 24 Jul 2003 14:11:15 +0200 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: oheinz@stud.fbi.fh-darmstadt.de, pgsql-sql@postgresql.org Subject: Re: Problem using Subselect results Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char 9C hex) in message header 'Received' Received: \234by rodos.fzk.de... ^ X-Archive-Number: 200307/358 X-Sequence-Number: 14472 > I want to use the result of a subselect as condition in another one. > > table1: a,b > table2: a,c > > CREATE VIEW my_view AS SELECT b,c > (SELECT a, b FROM table1 WHERE b=3D1) my_ab, > (SELECT c FROM table2, my_ab WHERE table3.a=3Dmy_ab.a) my_c; > > this is just an example - i know i could cross join this one, but i need = > to=20 > refer to the results of several subselects in several other. > > > does return "relation my_ab unknown". it is not just a problem of executi= > on=20 > order - if i turn it the other way round it's still the same. > > Am I just trying to do something really stupid? And what for is the (nece= > ssary)=20 > AS statement for subselects, if it's not possible to access their results= > by=20 > that name? > > And as I need the result of a subselect in several other subselects it's= > not=20 > possible to transform them into a cascade of sub, subsub, subsubsub.... s= > elects. > Any ideas?=20 > Does this match your intentions: CREATE VIEW my_view AS SELECT b,c FROM (SELECT b,c FROM table2, (SELECT a, b FROM table1 WHERE b=3D1) my_ab WHERE table3.a=3Dmy_ab.a) my_c; I assume the reference table3.a is a typo. Regards, Christoph