* Miretsky, Anya
> Select distinct
> biblio.* from biblio left join keyword on
> biblio.p_biblio=keyword.fk_biblio
> where keyword="SOMESTRING";

Try swapping the tables:

Select distinct
biblio.* from keyword left join biblio on
biblio.p_biblio=keyword.fk_biblio
where keyword="SOMESTRING";

The left join is used when there may exist rows in the left table which may
not have a related row in the right table, but you still want to include the
fields from the left table. The fields from the right table are all NULL in
the result row in this case.

In this case you probably don't need the left join:

Select distinct
  biblio.*
from
  keyword, biblio
where
  biblio.p_biblio=keyword.fk_biblio and
  keyword="SOMESTRING";

The above statements does not select anything from the keyword table, but
the where clause use the keyword table only, not the biblio table...

In your case you read all the biblio rows (11,901), and for each of them you
do a lookup on the related keywords matching "SOMESTRING"... this is rarely
what you want, the exception beeing when there are very very many keywords
and very few biblio rows. It is faster to use the index for all mathing
keywords, and then do the lookup to find the related biblio row.

By simply swapping the table names, you select FROM the keyword table, and
then join with the matching biblio rows.

--
Roger
query


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to