While reading some SQL Tuning-related documentation, I found this:
SELECT COUNT(*) :
- Counts the number of rows.
- Often is improperly used to verify the existence of a record.
Is SELECT COUNT(*) really that bad?
What’s the proper way to verify the existence of a record?
It’s better to use either of the following:
The first alternative should give you no result or one result, the second count should be zero or one.
How old is the documentation you’re using? Although you’ve read good advice, most query optimizers in recent RDBMS’s optimize
SELECT COUNT(*)anyway, so while there is a difference in theory (and older databases), you shouldn’t notice any difference in practice.