Google
 

Rabu, 19 November 2008

count(*) VS count(somefield)

What is the difference between "select count(*) from sometable" and "select count(somefield) from sometable"? The answer is simple, the "count(*)" will count all the record on that table. The "count(somefield)" will count all the record which is that field is not null. So the result of that 2 query may different. Example:
I have a table foo which has the record like this:

id name
1  XXXXX
2  YYYYY
3  
4  

select count(*) as cntall, count(name) as cntname from foo
The result of the above query is:
cntall cntname
4      2

Tidak ada komentar: