Is there any difference between COUNT('') and COUNT(*) and COUNT(1) and COUNT(ColumnName)? What approach is faster?
Is there any difference between COUNT(”) and COUNT(*) and COUNT(1) and COUNT(ColumnName) ? What
Share
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.
Count(ColumnName)is influenced by the value of the column. The other variants do effectively the same.Count(*)is slower in some databases (MySQL amongst others), because it retrieves all fields while it doesn’t have to. That’s whay often'x'or1is used to be safe. SQL Server and Oracle are somewhat smarter and don’t retrieve field values if they don’t have to.Note that
''equalsNULLon Oracle (yes it does!), which may have an undesired effect there. Not a problem for SQL Server, but you can use1to be safe.