X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id B9857D1B285 for ; Mon, 21 Jun 2004 07:11:29 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 19377-08 for ; Mon, 21 Jun 2004 10:11:23 +0000 (GMT) Received: from stan.ringways.co.uk (hub.ringways.co.uk [213.38.87.130]) by svr1.postgresql.org (Postfix) with ESMTP id 3097DD1B215 for ; Mon, 21 Jun 2004 07:11:18 -0300 (ADT) Received: from gary.ringways.co.uk ([10.1.1.2]) by stan.ringways.co.uk with esmtp (Exim 3.22 #1) id 1BcLkK-0005vd-00 for pgsql-sql@postgresql.org; Mon, 21 Jun 2004 11:09:48 +0100 Content-Type: text/plain; charset="us-ascii" From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@postgresql.org Subject: subselect prob in view Date: Mon, 21 Jun 2004 11:10:39 +0100 User-Agent: KMail/1.4.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200406211110.39940.gary.stainburn@ringways.co.uk> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200406/190 X-Sequence-Number: 18135 Hi folks, I've got the view: create view nrequest_details as select r.r_id, r_registration, r.r_chassis, r.r_vehicle, r.r_fuel,r.r_pack_mats, r.r_delivery, r_delivery::date-now()::date as r_remaining, r.r_created, r.r_completed, d.d_des, de.de_des, u.u_id, u.u_userid, u.u_username, u.u_salesman, u.u_target, t.t_id, t.t_des, s.s_id, s.s_des, c.c_id, c.c_des from requests r, users u, request_types t, request_states s, dealerships d, departments de, customers c where r_d_id = d.d_id and r_s_id = s.s_id and r_c_id = c.c_id and r_t_id = t.t_id and r_d_id = d.d_id and r_de_id = de.de_id and r_u_id = u.u_id; to which I want to add a count (2 eventually), so that it becomes: create view nrequest_details as select r.r_id, r_registration, r.r_chassis, r.r_vehicle, r.r_fuel,r.r_pack_mats, r.r_delivery, r_delivery::date-now()::date as r_remaining, r.r_created, r.r_completed, d.d_des, de.de_des, u.u_id, u.u_userid, u.u_username, u.u_salesman, u.u_target, t.t_id, t.t_des, s.s_id, s.s_des, c.c_id, c.c_des, co.count as comments -- cor.count as comments_unseen from requests r, users u, request_types t, request_states s, dealerships d, departments de, customers c left outer join (select co_r_id, count(co_r_id) from comments group by co_r_id) co on co.co_r_id = r.r_id -- left outer join (select co_r_id, count(co_r_id) from comments where cor_viewed is null -- group by co_r_id) co on -- co.co_r_id = r.r_id where r_d_id = d.d_id and r_s_id = s.s_id and r_c_id = c.c_id and r_t_id = t.t_id and r_d_id = d.d_id and r_de_id = de.de_id and r_u_id = u.u_id; but I get the error: [gary@eddie gary]$ psql -f goole1.sql DROP psql:goole1.sql:45: ERROR: Relation "r" does not exist [gary@eddie gary]$ I tried using the table name instead of the alias but instead got the error: [gary@eddie gary]$ psql -f goole1.sql psql:goole1.sql:1: ERROR: view "nrequest_details" does not exist psql:goole1.sql:45: NOTICE: Adding missing FROM-clause entry for table "requests" psql:goole1.sql:45: ERROR: JOIN/ON clause refers to "requests", which is not part of JOIN [gary@eddie gary]$ which at least makes sense. -- Gary Stainburn This email does not contain private or confidential material as it may be snooped on by interested government parties for unknown and undisclosed purposes - Regulation of Investigatory Powers Act, 2000