Should I use select count(*) from XXX
or select count(a, b, c.., z) from XXX
?
when counting the number of ro开发者_如何学运维ws in a query, which one is faster (if there is any difference in them) ?
Actually they are different. If for example a
has NULL values you will get only number of records where a
is not null. So you shoud use slect count (*) for counting the number of rows in a query
Well lcount(a,b,c,d) will produce a syntax error on most databases, you would need count(a),count(b),count(c),count(d).
If you want a count of the number of rows than use count(*).
If you want to count how many rows which have a not null value for a particular column then count(col).
Because with COUNT(*)
oracle counts the number of rows, and with COUNT(field)
it counts the number of values in field
that NOT NULL
. Which is obviously slower.
精彩评论