Re: 1 query or 2 queries

From: Date: Fri, 18 Jan 2002 14:39:31 +0000
Subject: Re: 1 query or 2 queries
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-15968@lists.php.net to get a copy of this message
Yes you can do that (that's what relational databases are all about). To join the two tables and fetch the data you need in a single query you would do something like this: SELECT Book.*, Chapter.* FROM Book, Chapter WHERE Book.BookTitle = Chapter.BookTitle Where "BookTitle" is whatever common element or key you have in both tables (this may be the title of the book, or a book ID, etc) - Patrick ----- Original Message ----- From: "George Pitcher" <fmdev@yahoo.co.uk> To: <php-db@lists.php.net> Sent: Friday, January 18, 2002 8:37 AM Subject: [PHP-DB] 1 query or 2 queries > I have a page that displays a book and some of its chapters (not all > chapters are recorded) and I want to do a layout like this: > > ISN: 012345678X > Book Title: A Christmas Carol > Book Author: Dickens, C. > Publisher: Victorian Press > Year: 1934 > > Dickens, C Chapter One:title 1-33 Last sold for 5p per page > Digitised > Dickens, C Chapter Two:title 34-43 Last sold for 5p per page > Digitised > Dickens, C Chapter Three:title 44-63 Not Cleared > Not Digitised > Dickens, C Chapter Six :title 92-114 Last sold for 5p per page > Digitised > > Now, I know I could do 2 queries, 1 against the book table and the other > against the chapter table. Would it be possible and if so more efficient to > combine them into a single query and still be able to display in this way? > > MTIA > > George in Edinburgh (data is fictional in more ways than one) > > > > --- > Outgoing mail is certified Virus Free. > Checked by AVG anti-virus system (http://www.grisoft.com). > Version: 6.0.314 / Virus Database: 175 - Release Date: 11/01/02 > > > _________________________________________________________ > Do You Yahoo!? > Get your free @yahoo.com address at http://mail.yahoo.com > > > -- > PHP Database Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-db-unsubscribe@lists.php.net > For additional commands, e-mail: php-db-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net > >

« previous php.db (#15968) next »