X-Original-To: pgsql-sql-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 67DBD9FA5C8 for ; Thu, 8 Jun 2006 12:52:05 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 71425-04 for ; Thu, 8 Jun 2006 12:51:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sccrmhc12.comcast.net (sccrmhc12.comcast.net [63.240.77.82]) by postgresql.org (Postfix) with ESMTP id 68EF29F9EF3 for ; Thu, 8 Jun 2006 12:51:56 -0300 (ADT) Received: from [10.0.1.6] (c-24-20-199-254.hsd1.or.comcast.net[24.20.199.254]) by comcast.net (sccrmhc12) with SMTP id <2006060815514801200su5ene>; Thu, 8 Jun 2006 15:51:49 +0000 Subject: Re: Query to return modified results at runtime? From: Kenneth B Hill Reply-To: ken@scottshill.com To: George Handin Cc: pgsql-sql@postgresql.org In-Reply-To: <44876F63.9030302@dafunks.com> References: <44876F63.9030302@dafunks.com> Content-Type: text/plain Organization: Scotts Hill Associates, Inc. Date: Thu, 08 Jun 2006 08:51:48 -0700 Message-Id: <1149781908.1645.14.camel@localhost> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200606/96 X-Sequence-Number: 25332 On Wed, 2006-06-07 at 19:29 -0500, George Handin wrote: > I have a query: > > SELECT * FROM testtable; > > Where the results are: > > ID Color > --- ------- > 1 Blue > 2 Red > 3 Green > 4 Orange > > How would I rewrite the query to return results where the colors are > replaced by letters to give the following results? > > ID Color > --- ------- > 1 A > 2 D > 3 B > 4 C > > ---------------------------(end of broadcast)--------------------------- > TIP 3: Have you checked our extensive FAQ? > > http://www.postgresql.org/docs/faq It looks like you may want to use a validation table: Name: color_validate ID Color Code --- --- --- 1 Blue A 2 Red D 3 Green B 4 Orange C Then try the following query: SELECT table_a.ID, color_validate.Code FROM table_a, color_validate WHERE (table_a.ID = color_validate.ID); -Ken