Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: Query that fetch whether any record exist
Ulrik Hoffmann wrote:
>
> What about
>
> select count(1) from
> tablename
> where ...
> and rownum < 2
>
> Returns 0 if not record exists, 1 if any record
> with the where clause exists. Stops reading
> after first row.
>
> Hth,
> Uli
>
> > 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.
> >
> > Any idea?
> >
> > Thanks,
> > Maoz
> >
> >
Also, EXPLAIN PLAN says that this might be even more efficient:
select 1 from dual where exists (select 1 from tableX where ...)
Yours,
Geoff Houck
systems hk
hksys_at_teleport.com
http://www.teleport.com/~hksys
Received on Sun Jan 09 2000 - 15:24:39 CST
![]() |
![]() |