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

Home -> Community -> Usenet -> c.d.o.server -> Re: Checking if more than 0 rows exist.

Re: Checking if more than 0 rows exist.

From: Walt <walt_askier_at_YerBootsyahoo.com>
Date: Mon, 09 May 2005 16:14:45 -0400
Message-ID: <VwPfe.1343$II.335@news.itd.umich.edu>


abc wrote:

> We have a table with 20 columns and many millions of records. I need to
> check if the combination of 5 of those columns exists anywhere in the table.
> It does not matter how many times it exists in the table but only if the
> combination exists in the table.
>
> Select count(*) from combo_table where all fields match would count them all
> but all I really need to know is if any exist (>0 rows).
>
> The fields are indexed so what I am wondering is what is the most efficient
> way to check that criteria? Any suggestions?

Select count(*)
from combo_table
where [your criteria here]
and rownum = 1

The above SQL will do more or less what you're looking for. I make no claims whether it's the most efficient way to do it.

Careful with rownum, though. It doesn't work the way most new users think it does.

-- 
//-Walt
Received on Mon May 09 2005 - 15:14:45 CDT

Original text of this message

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