pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Problem with a lookup table!  Please help.
5+ messages / 4 participants
[nested] [flat]

* Problem with a lookup table!  Please help.
@ 2002-12-09 20:58  Chris Jewell <vs0u8055@liv.ac.uk>
  0 siblings, 2 replies; 5+ messages in thread

From: Chris Jewell @ 2002-12-09 20:58 UTC (permalink / raw)
  To: pgsql-sql

Hi,

In my capacity as a vet student, I'm trying to create a database of antibiotics.  The way that I have set it up so far is to have one main table listing the antibiotics versus their respective efficacies against the four major groups of bacteria.  Due to the way that my PHP frontend works, I have assigned a number to the efficacy - 1 being excellent and 5 being poor efficacy against the particular bacterium.  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?

Regards,

Chris J

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Problem with a lookup table!  Please help.
@ 2002-12-09 21:08  Josh Berkus <josh@agliodbs.com>
  parent: Chris Jewell <vs0u8055@liv.ac.uk>
  1 sibling, 2 replies; 5+ messages in thread

From: Josh Berkus @ 2002-12-09 21:08 UTC (permalink / raw)
  To: Chris Jewell <vs0u8055@liv.ac.uk>; pgsql-sql


Chris,

> In my capacity as a vet student, I'm trying to create a database of 
antibiotics.  The way that I have set it up so far is to have one main table 
listing the antibiotics versus their respective efficacies against the four 
major groups of bacteria.  Due to the way that my PHP frontend works, I have 
assigned a number to the efficacy - 1 being excellent and 5 being poor 
efficacy against the particular bacterium.  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?

Please post your table definitions as SQL statements.


-- 
-Josh Berkus
 Aglio Database Solutions
 San Francisco




^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Problem with a lookup table!  Please help.
@ 2002-12-09 21:34  Jean-Luc Lachance <jllachan@nsd.ca>
  parent: Josh Berkus <josh@agliodbs.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Jean-Luc Lachance @ 2002-12-09 21:34 UTC (permalink / raw)
  To: josh@agliodbs.com; +Cc: Chris Jewell <vs0u8055@liv.ac.uk>; pgsql-sql

Use the AS keyword to introduce a column alias.

Select thisverlongtablename.thefirstfield as title, ... from 

JLL

Josh Berkus wrote:
> 
> Chris,
> 
> > In my capacity as a vet student, I'm trying to create a database of
> antibiotics.  The way that I have set it up so far is to have one main table
> listing the antibiotics versus their respective efficacies against the four
> major groups of bacteria.  Due to the way that my PHP frontend works, I have
> assigned a number to the efficacy - 1 being excellent and 5 being poor
> efficacy against the particular bacterium.  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?
> 
> Please post your table definitions as SQL statements.
> 
> --
> -Josh Berkus
>  Aglio Database Solutions
>  San Francisco
> 
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Problem with a lookup table!  Please help.
@ 2002-12-09 22:21  Chris Jewell <vs0u8055@liv.ac.uk>
  parent: Josh Berkus <josh@agliodbs.com>
  1 sibling, 0 replies; 5+ messages in thread

From: Chris Jewell @ 2002-12-09 22:21 UTC (permalink / raw)
  To: pgsql-sql

Hi,

Thanks for your reply.  Table definitions are:

CREATE TABLE tblantibiotics ('Antibiotic'
varchar(50),'Activity_against_grampos'  int,'Activity_against_gramneg'
int,'Activity_against_aerobes'  int,'Activity_against_anaerobes'  int);

CREATE TABLE efficacy ('Efficacy_code'  int,'Plain_english' varchar (10));

In table efficacy, 'Efficacy_code' contains a 1 - 5 scale of efficacy.  Each
string in 'Plain_english' is a plain English descriptor of the value in
'Efficacy_code'.  For example, 1 => Excellent, 2=> Good, etc etc.  What I
need to do is to substitute the integers set in the "Activity......."
columns in tblantibiotics with the strings in 'Plain_english' according to
the integer set in 'Efficacy_code'.  Any ideas?

Chris J



----- Original Message -----
From: "Josh Berkus" <josh@agliodbs.com>
To: "Chris Jewell" <vs0u8055@liverpool.ac.uk>; <pgsql-sql@postgresql.org>
Sent: Monday, December 09, 2002 9:08 PM
Subject: Re: [SQL] Problem with a lookup table! Please help.



Chris,

> In my capacity as a vet student, I'm trying to create a database of
antibiotics.  The way that I have set it up so far is to have one main table
listing the antibiotics versus their respective efficacies against the four
major groups of bacteria.  Due to the way that my PHP frontend works, I have
assigned a number to the efficacy - 1 being excellent and 5 being poor
efficacy against the particular bacterium.  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?

Please post your table definitions as SQL statements.


--
-Josh Berkus
 Aglio Database Solutions
 San Francisco





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: Problem with a lookup table!  Please help.
@ 2002-12-10 02:07  Oliver Elphick <olly@lfix.co.uk>
  parent: Chris Jewell <vs0u8055@liv.ac.uk>
  1 sibling, 0 replies; 5+ messages in thread

From: Oliver Elphick @ 2002-12-10 02:07 UTC (permalink / raw)
  To: Chris Jewell <vs0u8055@liv.ac.uk>; +Cc: 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.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 




^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2002-12-10 02:07 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-12-09 20:58 Problem with a lookup table!  Please help. Chris Jewell <vs0u8055@liv.ac.uk>
2002-12-09 21:08 ` Josh Berkus <josh@agliodbs.com>
2002-12-09 21:34   ` Jean-Luc Lachance <jllachan@nsd.ca>
2002-12-09 22:21   ` Chris Jewell <vs0u8055@liv.ac.uk>
2002-12-10 02:07 ` Oliver Elphick <olly@lfix.co.uk>

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