View Single Post

   
  #6 (permalink)  
Old 02-28-2008, 11:32 AM
Captain Paralytic
 
Posts: n/a
Default Re: Complex JOIN vs multiple selects

On 18 Jan, 12:34, Willem Bogaerts
<w.bogae...@kratz.maardanzonderditstuk.nl> wrote:
> >> And on the other hand, the join could cause some very large blob field
> >> to be transmitted for each row, whereas 3 queries would do this only
> >> once. So I guess the best answer is a bit situation-dependent.

>
> >> Regards,

>
> > And why would that be, Willem?

>
> If you have, for instance a book table and an author table, and a book
> is written by more than one author, you could write:
>
> SELECT book.content, author.name FROM book NATURAL JOIN author WHERE
> book.id=5;
>
> This would return the entire content of the book for each author
> (far-fetched example, I know). Whereas:
>
> SELECT content, @author_id:=authorId FROM book WHERE id=5;
> SELECT author.name FROM author WHERE id=@author_id;
>
> Would pass the content only once. So less data would go over the line,
> but effectively the exact amount of data is given, because the duplicate
> fields are removed.
>
> Or am I wrong in this?
>
> Regards,
> --
> Willem Bogaerts
>
> Application smith
> Kratz B.V.http://www.kratz.nl/


If book.id = 5 applied to more than one book then,
SELECT content, @author_id:=authorId FROM book WHERE id=5;
whould give you the content for every book where the id=5

Can't see the difference myself.
Reply With Quote