X-Original-To: pgsql-sql@postgresql.org Received: from localhost (developer.postgresql.org [64.117.224.193]) by developer.postgresql.org (Postfix) with ESMTP id 5CFEB925C40 for ; Fri, 30 May 2003 12:37:42 -0400 (EDT) Received: from developer.postgresql.org ([64.117.224.193]) by localhost (developer.postgresql.org [64.117.224.193:10024]) (amavisd-new) with ESMTP id 37701-05 for ; Fri, 30 May 2003 12:37:40 -0400 (EDT) Received: from davinci.ethosmedia.com (unknown [209.10.40.251]) by developer.postgresql.org (Postfix) with ESMTP id 88C23924F52 for ; Fri, 30 May 2003 12:37:40 -0400 (EDT) Received: from [63.195.55.98] (HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.0.2) with ESMTP id 3078959; Fri, 30 May 2003 09:37:44 -0700 Content-Type: text/plain; charset="iso-8859-1" From: Josh Berkus Organization: Aglio Database Solutions To: C F , pgsql-sql@postgresql.org Subject: Re: SQL Help Date: Fri, 30 May 2003 09:37:12 -0700 User-Agent: KMail/1.4.3 References: <20030530154703.37238.qmail@web20415.mail.yahoo.com> In-Reply-To: <20030530154703.37238.qmail@web20415.mail.yahoo.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-Id: <200305300937.12158.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new X-Archive-Number: 200305/571 X-Sequence-Number: 13736 CF, > select > (case when column1 = column2 then column3 end) as alias1, > (case when column1 = column2 then column4 end) as alias2, > (case when column1 = column2 then column5 end) as alias3, > (case when column6 = column7 then column8 end) as alias4 > from > mytable Given the information you've given us (including your first e-mail), I can't think of a better way to get the output you want than the above. You could work through subselects, etc, but I think that would be even less efficient. One thing you might want to think about is your whole approach to designing this application; it may be that you can simplify your queries by changing your table design. -- Josh Berkus Aglio Database Solutions San Francisco