X-Original-To: pgsql-general@postgresql.org Received: from spampd.localdomain (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 25320475A45 for ; Fri, 25 Apr 2003 04:38:33 -0400 (EDT) Received: from anchor-post-34.mail.demon.net (anchor-post-34.mail.demon.net [194.217.242.92]) by postgresql.org (Postfix) with ESMTP id 8FF26474E42 for ; Fri, 25 Apr 2003 04:38:31 -0400 (EDT) Received: from mwynhau.demon.co.uk ([193.237.186.96] helo=mainbox.archonet.com) by anchor-post-34.mail.demon.net with esmtp (Exim 3.35 #1) id 198yj2-000EkM-0Y; Fri, 25 Apr 2003 09:38:32 +0100 Received: from localhost (localhost.localdomain [127.0.0.1]) by mainbox.archonet.com (Postfix) with ESMTP id 89EC816855; Fri, 25 Apr 2003 09:38:31 +0100 (BST) Received: from client.archonet.com (client.archonet.com [192.168.1.16]) by mainbox.archonet.com (Postfix) with ESMTP id E5D1B166CC; Fri, 25 Apr 2003 09:38:30 +0100 (BST) Content-Type: text/plain; charset="iso-8859-1" From: Richard Huxton Organization: Archonet Ltd To: "jose antonio leo" , "pgsql-general" Subject: Re: Help with a query Date: Fri, 25 Apr 2003 09:38:50 +0100 User-Agent: KMail/1.4.3 References: In-Reply-To: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Message-Id: <200304250938.51060.dev@archonet.com> X-Virus-Scanned: by AMaViS snapshot-20020531 X-Spam-Status: No, hits=-38.9 required=5.0 tests=BAYES_01,EMAIL_ATTRIBUTION,IN_REP_TO,QUOTED_EMAIL_TEXT, REFERENCES,REPLY_WITH_QUOTES,USER_AGENT_KMAIL autolearn=ham version=2.50 X-Spam-Level: X-Spam-Checker-Version: SpamAssassin 2.50 (1.173-2003-02-20-exp) X-Archive-Number: 200304/1320 X-Sequence-Number: 41385 On Friday 25 Apr 2003 8:41 am, jose antonio leo wrote: > aec_cua_man: > ac1-ac2-ac3 > 1-1-1 > 1-1-2 > 1-1-4 > 1-2-2 > .... > > aecoc: > ac1-ac2-ac3-description > 1-0-0-des1 > 1-1-0-des2 > 1-1-1-des3 > 1-1-2-des4 > 1-1-3-des5 > 1-1-4-des6 > 1-1-5-des7 > 1-2-0-des8 > 1-2-1-des9 > 1-2-2-des10 > .... > > I need the record of the first table with the fields ac1, ac2 and ac3 > equals than second table but in addition the fiels of the second table wi= th > a nul in the fiels ac2 and ac3. > > the table result will be: > 1-0-0-des1 > 1-1-0-des2 > 1-1-1-des3 > 1-1-2-des4 > 1-1-4-des6 > 1-2-0-des8 > 1-2-2-des10 > > Could you help me? Simplest method might be a union - do the join on the 3 fields and union it= =20 with a simple select on aecoc where ac3=3D0 or ac2=3D0. Syntax is something= like: SELECT ac1,ac2,ac3,description FROM .... (join here) UNION SELECT ac1,ac2,ac3,description FROM aecoc... (grab zero descriptions here) Note that the order of the result columns should be the same in both cases.= If=20 you know there will be no zeros in aec_cua_man then you might want to use= =20 UNION ALL. See the User's guide Ch4 or the SQL SELECT reference for some details. --=20 Richard Huxton