Re: Question: select that just detects a matching row

From: Jeff Masteller <jmast_at_earthlink.net>
Date: 1996/12/12
Message-ID: <32AFFC89.2C59_at_earthlink.net>#1/1


I would try several approaches and analyze the plan try what what Johm says
and then try it again with a "first rows hint"

then through in rownum=1 with and with out the hint

John Eccleston wrote:
>
> Chris asked:
> >I have many places in my application where the user can enter some
> >search criteria, a date lets say, and then makes a request against a
> >table just to see whether any rows matching the criteria are present. In
> >this part of the application, I'm not interested in actually getting the
> >data from the table, or even how many rows match the criteria, I just
> >want to see if some row in the table matches the criteria. What I'm
> >doing now of course is a "select count(*) from table_name where column
> >name = search_criteria". I don't need the total count, and I've got a
> >performance problem with running this query against the tables. Is
> >there any function that's faster that this that will stop and return a
> >"true" value when it encounters the first row that matches the where
> >clause, instead of scanning through all rows and counting them up, in my
> >case unneccesarily? Any ideas would be appreciated...
> >
> >Chris
>
> Hi Chris,
>
> You could try using EXISTS
>
> e.g.:
>
> SELECT
> 1
> FROM
> dual
> WHERE
> EXISTS
> (SELECT
> 1
> FROM
> table_name
> WHERE
> column_name = criteria);
>
> As far as I remember exists will quit as soon as it finds a matching row.
>
> Hope this helps
>
> Regards
>
> John
>
  Received on Thu Dec 12 1996 - 00:00:00 CET

Original text of this message