I seem to remember that (on Oracle) there is a difference between uttering select count(*) from any_table
and select count(any_non_null_column) from any_table
.
What are the differences between these two statements, if any?
aggregatecountnulloracle
I seem to remember that (on Oracle) there is a difference between uttering select count(*) from any_table
and select count(any_non_null_column) from any_table
.
What are the differences between these two statements, if any?
Best Answer
This means
COUNT(any_non_null_column)
will give the same asCOUNT(*)
of course because there are no NULL values to cause differences.Generally,
COUNT(*)
should be better because any index can be used becauseCOUNT(column_or_expression)
may not be indexed or SARGableFrom ANSI-92 (look for "
Scalar expressions 125
")The same rules apply to SQL Server and Sybase too at least
Note: COUNT(1) is the same as COUNT(*) because 1 is a non-nullable expression.