sorry for my confusing email... i'll try to clarify what i was asking:

i have two tables (i shortened them to only show the parts relating to what
i'm trying to do now) ...

CREATE TABLE articles (
  id smallint(4) unsigned zerofill NOT NULL auto_increment,
  title varchar(40) NOT NULL default '',
  public char(1) NOT NULL default 'y',
  author smallint(6) default NULL,
  editor smallint(6) default NULL,
  photog1 smallint(6) default NULL,
  photog2 smallint(6) default NULL,
  PRIMARY KEY  (id),
  KEY author (author),
  KEY editor (editor),
  KEY photog1 (photog1),
  KEY photog2 (photog2),
) TYPE=MyISAM;

CREATE TABLE people (
  id tinyint(3) unsigned NOT NULL auto_increment,
  name varchar(30) NOT NULL default '',
  PRIMARY KEY  (id),
) TYPE=MyISAM;

those are my two tables. basically 'articles' holds all of the info relating
to that article, and people just contains all the possible people that might
be an author, editor, or photographer. when i display an article, it queries
the database a total of 5 times. (once to retrieve all of the info from
'articles' and 4 more times to retrieve info from 'people.'

i know that this isn't that efficient. i wish to use JOINs so that only 1
query would be made, and that the name of the author, editor, etc can be
pulled up instead of just their index values (which i know query the
database again to pull out the name).

i have a feeling i would need a rather complex JOIN but i'm not sure how it
looks exactly.

any help would be appreciated.

thank you very much.
-jon


-----Original Message-----
From: David Elliott [mailto:[EMAIL PROTECTED]]
Sent: Friday, November 22, 2002 2:18 AM
To: Jonathan Narong on PHP-DB
Subject: Re: regarding multiple joins


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Greetings Jonathan

On 22 November 2002 at 01:55:10 -0800 (which was 09:55 where I live)
Jonathan Narong graced us with these comments

> i have an table 'articles' which has multiple fields, such as author,
> editor, photographer, etc.. each of these fields contains an index number
> which relates to another table 'people' that lists everyone. basically i
> just want to select  everything with the names displaying, instead of id
> numbers.

not sure exactly what you want.

I have a table called country. It contains all ID's.The name of which is in
an item table, so it has to use the item table a number of time so that it
can display just names to the user and not ID's

========== One I made earlier =============================================
select
  a.ItemId CID
  ,b.name country
  ,c.name Currency
  ,d.name Region
  ,e.name VAT
  ,f.name Delivery
from
  country a
  ,item b
  ,item c
  ,item d
  ,item e
  ,item f
where
  a.itemid = b.itemid
  and a.CurrId = c.itemid
  and a.GeoRegId = d.itemid
  and a.VaTID = e.itemid
  and a.DelID = f.itemid
order by f.name
========== One I made earlier =============================================

HTH

- --
 Best regards,             _______________________________________________
  David                   |    David  Elliott    |   Software Engineer    |
 _________________________| [EMAIL PROTECTED] | PGP Key ID 0x650F4534  |
| "It should be a while...he's very thorough." -- Trapper on Hawkeye      |

-----BEGIN PGP SIGNATURE-----
Version: 6.5.8ckt http://www.ipgpp.com/

iQA+AwUBPd4EYvmK8eZlD0U0EQLBuwCWJZVbOfWxqmMd+4KgqKmIgRs3agCggA2g
qzjRbhBT9szMn6EJI4lHZhE=
=e0St
-----END PGP SIGNATURE-----




-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to