Sp00kyy Sp00kyy - 1 year ago 56
SQL Question

My table has lots of values in a column, however when I run a COUNT query lots of values are missing

As my title says, I am trying to run a query using COUNT, however the results are not what I am expecting at all. I have run the following query:

SELECT AdmissionReason FROM Episode

I have resulted in 70150 rows.
I have then run the following query and I get 0 results. This isn't possible as I know for a fact there are 1000's of rows with a NULL.

SELECT COUNT(AdmissionReason) FROM Episode
WHERE AdmissionReason IS NULL;

I was expecting this query to give me a count of all episodes where the AdmissionReason is null, however I am getting a result of 0.

Could I be missing something here?

Answer Source

COUNT(SomeColumn) doesn't count NULL. So COUNT(NULL's) = 0

try with

FROM Episode
WHERE AdmissionReason IS NULL;


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download