you could do this with a join, but i experienced single querys to be faster if
you always have only one person_id to look for in person.
if it was many person_ids and your query would end like "...person_id in
(1,2,3...., 9998)" a join would by faster, I guess.

feal free to correct me, if I'm wrong :-)

btw: a join could look like this:
SELECT * FROM article AS a LEFT JOIN person AS p1 ON a.author_id=p1.person_id
LEFT JOIN person AS p2 ON a.editor_id=p2.person_id LEFT JO......

So with saving time() befor and after the query(s) you can do your own


Jonathan Narong schrieb:

> this is a problem i've been struggling with for a little while. any attempt
> to find help online has not produced any useful information. this is
> regarding joins, which i'm not an expert in, but hopefully one of you can
> help me out.
> 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.
> the way i'm currently doing this is pretty inefficient; on the display page,
> i have multiple queries. first to extract everything from the articles
> table, and then a query for each field (i.e. SELECT name FROM authors WHERE
> (author_id = $id). This works, although I'm pretty sure there's a much more
> efficient way of doing this with one query.
> I know a method would be to have separate tables for authors, editors,
> photographers, etc... but in this case, it would be simpler to just relate
> everything to the one "people" table. THis is because any particular person
> could take on multiple tasks, or different ones, for different articles.
> Hope this all makes sense. I have a feeling aliases will be need to used,
> although I'm not exactly sure how.
> Thanks for any help you guys might be able to provide. ;-)
> -jon

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

Reply via email to