开发者

Should I use count(*) or count(a, b, c.., z) when counting the number of rows in a query?

开发者 https://www.devze.com 2023-01-26 11:24 出处:网络
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) ?Ac

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消