Re: Problem with a lookup table! Please help.

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Chris Jewell <vs0u8055(at)liv(dot)ac(dot)uk>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Problem with a lookup table! Please help.
Date: 2002-12-10 02:07:54
Message-ID: 1039486074.20146.43.camel@linda.lfix.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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(dot)Elphick(at)lfix(dot)co(dot)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

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Elizabeth O'Neill's Office Mail 2002-12-10 12:27:34 SQL syntax for concating values in different rows together
Previous Message 2000 Informática 2002-12-10 01:53:56 Re: ISNULL FUNCTION