Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can Count(*) ever return null? [duplicate]

Possible Duplicate:
Does COUNT(*) always return a result?

Is it possible in any scenario for the Count() function to return NULL?

like image 267
m.edmondson Avatar asked Feb 11 '11 14:02

m.edmondson


People also ask

Does count (*) ignore NULL values?

COUNT does not include NULL values in column counts. Therefore, the number of return values for each column might differ or be less than the total number of rows returned by COUNT(*).

Does Count return NULL in SQL?

COUNT never returns null. The following example calculates, for each employee in the employees table, the moving count of employees earning salaries in the range 50 less than through 150 greater than the employee's salary.

What does the count (*) command return?

The COUNT(*) function returns a number of rows in a specified table or view that includes the number of duplicates and NULL values.

Does Count return 0 or NULL?

As all of your values are null, count(cola) has to return zero.


2 Answers

No, it will only return a zero (or non-zero) result. SqlServer will not return null.

like image 120
Simon Avatar answered Sep 19 '22 11:09

Simon


According to the MSDN page, no.

That said:

For return values greater than 2^31-1, COUNT produces an error. Use COUNT_BIG instead.

like image 23
Matt Ball Avatar answered Sep 19 '22 11:09

Matt Ball