Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: ANDing across tables

Re: ANDing across tables

From: Marshall Barton <marshbarton_at_Mindspring.com>
Date: Wed, 15 Aug 2001 18:19:12 -0500
Message-ID: <9levt2$ss2$1@slb3.atl.mindspring.net>

Try something like this air code to see if it's faster:

Select imkw.im_id From imkw

    INNER JOIN keyword

        ON imkw.kw_id = keyword.id
Where keyword.keyword = "kimono"

    OR keyword.keyword = "shrine"
Group By imkw.im_id
Having COUNT(*)=2

It may make a significant difference if there is a unique index on the keyword.keyword field.

abracad wrote in message
<3b7ae22d.6169125_at_news.freeserve.net>...
>I have a database of images, each of which is described by
 n keywords.
>The data is held in 3 tables:
>image: description, id
>keyword: keyword, id
>imkw: im_id, kw_id
>
>I would like to run a query which retrieves images having 2
 (or more
>keywrods)
>
>I can achieve this thus:
>SELECT image.id, COUNT(*)
>FROM image, imkw, keyword
>WHERE image.id=imkw.im_id AND imkw.kw_id=keyword.id AND
 keyword IN
>("kimono", "shrine")
>GROUP BY image.ID
>HAVING COUNT(*)=2
>
>But I would like to know if there is a more efficient means
 of running
>such and AND search.
>
>Many thanks in advance for any advice.
>
Received on Wed Aug 15 2001 - 18:19:12 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US