MySQL Forums
Forum List  »  PHP

Re: exist
Posted by: Martin Hall
Date: June 27, 2005 04:24PM

SELECT COUNT(*) > 0 FROM tablename WHERE username='$username';

will return 1 (true) if there are any records in the table named 'mytable' where the username is $username and 0 (false) if there aren't.

This interests me, as I often need to establish whether a matching record exists
without necessarily retrieving the record.

Can you say how your solution compares, performance-wise, with this:
SELECT * FROM tblname WHERE field = '$data'
and then returning a count of the resulting record-set

Thanks in advance.

Options: ReplyQuote

Written By
June 03, 2005 09:27AM
June 04, 2005 10:40AM
Re: exist
June 27, 2005 04:24PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.