From: Oliver Elphick <olly@lfix.co.uk>
To: Chris Jewell <vs0u8055@liv.ac.uk>
Cc: pgsql-sql@postgresql.org
Subject: Re: Problem with a lookup table! Please help.
Date: 10 Dec 2002 02:07:54 +0000
Message-ID: <1039486074.20146.43.camel@linda.lfix.co.uk> (raw)
In-Reply-To: <000f01c29fc5$afc34960$2301a8c0@chrisdomain>
References: <000f01c29fc5$afc34960$2301a8c0@chrisdomain>
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
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 using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: olly@lfix.co.uk, vs0u8055@liv.ac.uk
Subject: Re: Problem with a lookup table! Please help.
In-Reply-To: <1039486074.20146.43.camel@linda.lfix.co.uk>
* 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