I have always used * for queries like this where columns don't really matter because they arent being returned:
SELECT COUNT(*) FROM ...
or
WHERE EXISTS (SELECT * FROM ...
Recently I've seen other SQL developers replacing the * with a 1 in these scenarios. Since the columns aren't really being returned, it there really any advantage to using the 1 over the *?
After researching the issue, I've found that it is really just personal preference. I'll stick with COUNT(*).
snaps & snippets: What's wrong with COUNT(*)?: "One thing is certain, though, select count(1) does not perform any better than select count(*). And I've tried using other constants as well – no change. Is that another myth busted? Can anyone confirm this or prove otherwise?"
Thursday, August 7, 2008
Subscribe to:
Post Comments (Atom)

No comments:
Post a Comment