I have two choices when writing an SQL statement with the COUNT
function.
SELECT COUNT(*) FROM <table_name>
SELECT COUNT(some_column_name) FROM <table_name>
In terms of performance, what is the best SQL statement? Can I obtain some performance gain by using option 1?
Performance should not matter because they do 2 different aggregates
COUNT(*)
is all rows, including NULLsCOUNT(some_column_name)
, excludes NULL in "some_column_name
"See the "Count(*) vs Count(1)" question for more
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With