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 4D361D1BA8F for ; Tue, 9 Mar 2004 22:41: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 88522-06 for ; Tue, 9 Mar 2004 18:40:50 -0400 (AST) Received: from mta03-svc.ntlworld.com (mta03-svc.ntlworld.com [62.253.162.43]) by svr1.postgresql.org (Postfix) with ESMTP id 6A28FD1C95E for ; Tue, 9 Mar 2004 18:40:47 -0400 (AST) Received: from apple.at.home ([80.1.223.30]) by mta03-svc.ntlworld.com (InterMail vM.4.01.03.37 201-229-121-137-20020806) with ESMTP id <20040309224018.DVYP5865.mta03-svc.ntlworld.com@apple.at.home> for ; Tue, 9 Mar 2004 22:40:18 +0000 Received: from localhost (localhost [127.0.0.1]) by apple.at.home (Postfix) with ESMTP id B8D4D1EE61 for ; Tue, 9 Mar 2004 22:41:33 +0000 (GMT) Received: from orange.keep-trying.com (orange.at.home [192.168.5.30]) by apple.at.home (Postfix) with ESMTP id 32790EAA8 for ; Tue, 9 Mar 2004 22:41:32 +0000 (GMT) Message-Id: <6.0.0.22.0.20040309223517.0351e328@192.168.5.1> X-Sender: richard@192.168.5.1 X-Mailer: QUALCOMM Windows Eudora Version 6.0.0.22 Date: Tue, 09 Mar 2004 22:40:33 +0000 To: pgsql-sql@postgresql.org From: Richard Grosse Subject: Converting query to view - duplicate fields Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd 0.1 X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/95 X-Sequence-Number: 17194 Hello, Trying to convert the query below to a view. The problem is despite it working as a query when trying to save it as a view the database returns the error that the field tablealias.cmpname is duplicated. (Which it is and has to be) So how to a refer to the same table more than once and get the data without getting the above error. (Basically it is looking up different addresses depending on the codes stored in mhdespatch table). Can I do this with a view, or do I have to create several views and link them together. Thanks Richard Postgresql 7.4.1,SuSE 8.1 Query Begins ==> CREATE OR REPLACE VIEW public.test AS SELECT mhdespatch.gdn, mhdespatch.date, mhdespatch.remarks, mhdespatch.sp_instruct1, mhdespatch.sp_instruct2, mhdespatch.sp_instruct3, tbldelivery.cmpname, tbldelivery.adds1, tbldelivery.adds2, tbldelivery.adds3, tbldelivery.town, tbldelivery.county, tbldelivery.pcode, tbldelivery.country, tbldelivery.tel1, mhdespatch.del_ref, tblsender.cmpname, mhdespatch.send_ref, tblhaulier.cmpname, mhdespatch.haul_reg, mhdespatch.cov, tblhaulier.tel1 FROM mhdespatch INNER JOIN tblfmna AS tblhaulier ON mhdespatch.haul_code = tblhaulier.code INNER JOIN tblfmna AS tblsender ON mhdespatch.send_code = tblsender.code INNER JOIN tblfmna AS tbldelivery ON mhdespatch.del_code = tbldelivery.code; <=== Query Ends