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 7162ED1B4E1 for ; Fri, 31 Oct 2003 13:48:27 +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 97529-09 for ; Fri, 31 Oct 2003 09:47:59 -0400 (AST) Received: from matrix.gatewaynet.com (unknown [217.19.69.50]) by svr1.postgresql.org (Postfix) with ESMTP id 0A337D1B555 for ; Fri, 31 Oct 2003 09:47:54 -0400 (AST) Received: from matrix.gatewaynet.com (localhost.localdomain [127.0.0.1]) by matrix.gatewaynet.com (8.12.8/8.12.8) with ESMTP id h9VDlndN014470; Fri, 31 Oct 2003 15:47:49 +0200 Received: from localhost (achill@localhost) by matrix.gatewaynet.com (8.12.8/8.12.8/Submit) with ESMTP id h9VDln5J014466; Fri, 31 Oct 2003 15:47:49 +0200 Date: Fri, 31 Oct 2003 15:47:49 +0200 (EET) From: Achilleus Mantzios To: Frank Morton Cc: pgsql-sql@postgresql.org Subject: Re: conditional query? In-Reply-To: <5D07F76A-0BA6-11D8-A615-000A95A83378@base2inc.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200310/412 X-Sequence-Number: 15812 Why dont you try a combination of CASE WHEN ... THEN ... ELSE ... END construct along with a LEFT OUTER join (in case parentId is null). Not sure how "portable" the above will be. O kyrios Frank Morton egrapse stis Oct 31, 2003 : > I have a table called a "profile" that has company addresses as well > as individual contact information. Simpifying: > > id (the primary key) > parentId (any profile can have a parent ie, contact parent is a company) > address (for this example, will just have one piece of the address) > useParentAddress > > If "useParentAddress"=="Y", that means that the parent address of this > person should really be used for mailings. If == "N" then the address > with that profile is the right one to use. > > Is there any way to do a single select to get a single "address" back > that is the right one depending on the value of "useParentAddress" > field? > > Also want to make this sql as portable as possible. > > Will appreciate any ideas. > > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings > -- -Achilleus