Hi.

On Tue, May 28, 2002 at 06:51:11PM -0400, [EMAIL PROTECTED] wrote:
> How do you reference a column name in another table to avoid repeating the
> values?

I am not sure if I understand you correctly, but I assume you mean this:

Given the following table layout (it's a simplification in that I
presume that there is only one author per book):

CREATE TABLE book (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(100) NOT NULL,
  author VARCHAR(100) NOT NULL,
  <...>
);

I could change it to

CREATE TABLE author (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  <...>
);

CREATE TABLE book (
  id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
  title VARCHAR(100) NOT NULL,
  author_id INT OT NULL,
  <...>
);

So there reference is by the INT id field and you select it like this:

SELECT b.title, a.name 
FROM   book b, author a
WHERE  a.id = b.author_id AND
       <some condition to select the book(s) you are interested in)

Hope that answered your question. Btw, this is quite basic database
stuff, so you may want to consider to read a good book or tutorial on
the topic. See http://www.mysql.com/portal/.

Bye,

        Benjamin.

-- 
[EMAIL PROTECTED]

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to