Difference between checking count(*) and if Exists

EXISTS keyword to perform an existence check is almost always faster than using COUNT(*). EXISTS can stop as soon as the logical test proves true, but COUNT(*) must count every row, even after it knows one row has passed the test.

Normally, EXISTS is the right way and COUNT(*) the wrong way. If you want to check for existence, stop at the first match, and don’t waste time on counting them all.

Leave a comment