how to select custom value when exists otherwise select default

From: patrick <none(at)nowhere(dot)fr>
To: pgsql-sql(at)postgresql(dot)org
Subject: how to select custom value when exists otherwise select default
Date: 2005-02-14 23:26:33
Message-ID: 421133db$0$6585$8fcfb975@news.wanadoo.fr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql


I use a select like this:
SELECT sometables
WHERE field0='a' or field0='b' or field0='c'
and field4='m' or field4='n'
ORDER BY field0;

m.field4 is default value
n.field4 is custom value

I want only n(custom) if it exists ortherwise I want m(default)
but I do not want both!

I mean I have this result:
table{
field0 {a,a,b,c}
field1 {d,d,e,f}
field2 {g,g,h,i}
field3 {j,j,k,l}
field4 {m,n,m,m}
}
a.filed0 has 2 results, one for m(default) and one for n(optionnal)
b and c have no custom value so field4 is set to m for them

and I want this result:
table{
field0 {a,b,c}
field1 {d,e,f}
field2 {g,h,i}
field3 {j,k,l}
field4 {n,m,m}
}

of course I'm looking for only one request to do that, and I'd rather a
lighter one ;-)

Browse pgsql-sql by date

  From Date Subject
Next Message Theo Galanakis 2005-02-15 03:46:59 Re: Working with XML.
Previous Message PFC 2005-02-14 20:06:50 Re: triggers