On Wed, 10 Nov 2004 09:04:27 -0900, Chris Lott <chris.lott@xxxxxxxxx> wrote: > Given a database query thats returns results from a linking (or xref) > table which includes repetition because of the joins: > > +----+--------------------------+----------+ > | id | title | subject | > +----+--------------------------+----------+ > | 1 | Collected Poems of Keats | poetry | > | 2 | Spy High | suspense | > | 3 | Sci Fi Spies | suspense | > | 3 | Sci Fi Spies | sci-fi | > +----+--------------------------+----------+ > > What is the best way to go about displaying this for the user so that > the record looks "complete": > > ID: 3 > title: Sci Fi Spies > Subjects: suspense, scifi You might normalize the data a bit. I'd go with three tables: books, subjects, and a books_subjects_xref table. The subjects table would contain the subject_id and the subject. The books table would contain the book_id and book_title. The books_subjects_xref table will contain the book_id and subject_id, with a two-field unique constraint on book_id and subject_id. You would have an entry for each subject a book is in. As far as the sql, I'd suggest something but you didn't say what db you're using. Looks like MySQL output but I could be wrong. -- Greg Donald Zend Certified Engineer http://gdconsultants.com/ http://destiney.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php