I have a table and want to check if there exists any record which satisfies some simple condition.
I’d like to know which will work faster:
if (select count(*) from ... where ...) > 0
or
if exists (select top (1) from ... where ...) .
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
exists returns result as soon as it finds record with matching where-clause while count needs to scan whole table to determine count. So exists is faster