Re: Query that fetch whether any record exist

From: Remco Blaakmeer <remco_at_rd1936.quicknet.nl>
Date: 10 Jan 2000 00:06:06 GMT
Message-ID: <85b7pe$95k$1_at_rd1936.quicknet.nl>


[Quoted] In article <85ad31$jeh$1_at_news.netvision.net.il>,

        "Maoz Mussel" <maoz_at_mindcti.com> writes:
> What is the fastest method to check whether ANY record satesfy the
> WHERE clause? For example, the following query:
> SELECT COUNT (*) FROM tableX
> WHERE ...
> May require full table scan in order to return number of records with the
> specified criteria. Same with any MIN function usage, while all I want is
> a boolean value specifying whether any record exist, i.e. one that will
> stop execution once the first record is found.

SELECT 'yes, a record satisfies the WHERE clause' FROM dual
WHERE EXISTS ( SELECT 'x' FROM tablea WHERE ... )

The EXISTS clause will return TRUE at the first row returned from the subquery. No more than one row will be fetched from the subquery.

Remco

-- 
rd1936: 12:55am  up 1 day,  5:34,  8 users,  load average: 2.54, 2.33, 2.33
Received on Mon Jan 10 2000 - 01:06:06 CET

Original text of this message