Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 8AD0E47639A for ; Mon, 9 Dec 2002 21:08:40 -0500 (EST) Received: from anchor-post-33.mail.demon.net (anchor-post-33.mail.demon.net [194.217.242.91]) by postgresql.org (Postfix) with ESMTP id 16B18476609 for ; Mon, 9 Dec 2002 21:07:52 -0500 (EST) Received: from lfix.demon.co.uk ([158.152.59.127] helo=linda.lfix.co.uk) by anchor-post-33.mail.demon.net with esmtp (Exim 3.35 #1) id 18LZoR-000PTN-0X; Tue, 10 Dec 2002 02:07:55 +0000 Received: from localhost ([127.0.0.1] ident=olly) by linda.lfix.co.uk with esmtp (Exim 3.36 #1 (Debian)) id 18LZoQ-0005bU-00; Tue, 10 Dec 2002 02:07:54 +0000 Subject: Re: Problem with a lookup table! Please help. From: Oliver Elphick To: Chris Jewell Cc: pgsql-sql@postgresql.org In-Reply-To: <000f01c29fc5$afc34960$2301a8c0@chrisdomain> References: <000f01c29fc5$afc34960$2301a8c0@chrisdomain> Content-Type: text/plain Organization: LFIX Limited Message-Id: <1039486074.20146.43.camel@linda.lfix.co.uk> Mime-Version: 1.0 X-Mailer: Ximian Evolution 1.2.0 Date: 10 Dec 2002 02:07:54 +0000 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/110 X-Sequence-Number: 10698 On Mon, 2002-12-09 at 20:58, Chris Jewell wrote: > ... > However, I now want to have a new table which converts numbers into > words. The problem is this, if I join the main table with the > "translation" lookup table, the column names for each of the four > categories in the main default to the column name in the lookup table > and hence are all the same. What SQL expression should I use to > translate the cryptic numbers into plain english whilst preserving the > column headings in the main table? You just need to name the columns: SELECT t.antibiotic, e1.plain_english AS "Activity against grampos", e2.plain_english AS "Activity against gramneg", e3.plain_english AS "Activity against aerobes", e4.plain_english AS "Activity against anaerobes" FROM tblantibiotics AS t, efficacy AS e1, efficacy AS e2, efficacy AS e3, efficacy AS e4 WHERE t.activity_against_grampos = e1.efficacy_code AND t.activity_against_gramneg = e2.efficacy_code AND t.activity_against_aerobes = e3.efficacy_code AND t.activity_against_anaerobes = e4.efficacy_code; Note that you must use double quotes to quote identifiers, not single quotes as you did in your table creation definitions, which won't work in PostgreSQL. -- Oliver Elphick Oliver.Elphick@lfix.co.uk Isle of Wight, UK http://www.lfix.co.uk/oliver GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C ======================================== "I beseech you therefore, brethren, by the mercies of God, that ye present your bodies a living sacrifice, holy, acceptable unto God, which is your reasonable service." Romans 12:1