do a
SELECT COUNT(*) FROM <tablename> WHERE ...

A count is almost always faster than actually returning that row, and
requires even less network bandwidth to return the result. Of course, it a
result of 1 is returned - the row exists.

Steve H.

-----Original Message-----
From: Steven Lembark [mailto:[EMAIL PROTECTED]]
Sent: Saturday, July 07, 2001 11:54 AM
To: [EMAIL PROTECTED]
Subject: Re: Checking for the existence of a certain row.


- James Kufrovich <[EMAIL PROTECTED]> on 07/06/01 17:08:56 -0400:


>       I'd like to check for the existence of data in a row of a database
> (MySQL), if given the value of a primary key.  ("Is there already a row in
> the database that has this value as a key?") I don't care what data is in
> the row, or if more than one row (!!) is found.  I'd hope that whatever
> method I use will stop searching the database after it finds the first
> match.
>
>       What would be the best way to go about this? Is there a special
> method that can do this, or would I have to use selectrow_array (or
> fetchrow_array or one of those) and then see if it finds anything?  I
> suppose I can call 'finish' as soon as a match is found, if the method (or
> whatever) doesn't stop by itself.  I'd appreciate any tips. Thanks.

    select keyfield1, keyfield2,... keyfieldN from tablename;

If the list of keyfield's is your PK then this should return rather quickly.

Reply via email to