X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id EB1828BA007 for ; Mon, 14 Feb 2005 23:27:26 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 87656-06 for ; Mon, 14 Feb 2005 23:27:25 +0000 (GMT) Received: from floppy.pyrenet.fr (news.pyrenet.fr [194.250.190.2]) by svr1.postgresql.org (Postfix) with ESMTP id 3268E8B9FF6 for ; Mon, 14 Feb 2005 23:27:25 +0000 (GMT) Received: by floppy.pyrenet.fr (Postfix, from userid 106) id 156E731E32; Tue, 15 Feb 2005 00:27:25 +0100 (MET) Message-Id: <421133db$0$6585$8fcfb975@news.wanadoo.fr> From: patrick Subject: how to select custom value when exists otherwise select default X-Newsgroups: pgsql.sql Date: Tue, 15 Feb 2005 00:26:33 +0100 Organization: a MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7Bit Lines: 35 X-Complaints-To: abuse@wanadoo.fr To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200502/175 X-Sequence-Number: 20286 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 ;-)