[SQL] Problem with a lookup table! Please help.

2002-12-09 Thread Chris Jewell



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


Re: [SQL] Problem with a lookup table! Please help.

2002-12-09 Thread Chris Jewell
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" <[EMAIL PROTECTED]>
To: "Chris Jewell" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
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



---(end of broadcast)---
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/users-lounge/docs/faq.html