pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Achilleus Mantzios <achill@matrix.gatewaynet.com>
To: Frank Morton <fmorton@base2inc.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: conditional query?
Date: Fri, 31 Oct 2003 15:47:49 +0200 (EET)
Message-ID: <Pine.LNX.4.44.0310311544270.13725-100000@matrix.gatewaynet.com> (raw)
In-Reply-To: <5D07F76A-0BA6-11D8-A615-000A95A83378@base2inc.com>


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




view thread (4+ messages)  latest in thread

Message-ID: <Pine.LNX.4.44.0310311544270.13725-100000@matrix.gatewaynet.com>
Permalink:  ../Pine.LNX.4.44.0310311544270.13725-100000@matrix.gatewaynet.com/
Also on:    postgresql.org/message-id/Pine.LNX.4.44.0310311544270.13725-100000@matrix.gatewaynet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: achill@matrix.gatewaynet.com, fmorton@base2inc.com
  Subject: Re: conditional query?
  In-Reply-To: <Pine.LNX.4.44.0310311544270.13725-100000@matrix.gatewaynet.com>
  References: <5D07F76A-0BA6-11D8-A615-000A95A83378@base2inc.com> <Pine.LNX.4.44.0310311544270.13725-100000@matrix.gatewaynet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox