Reputation: 9233
I am doing count functions on two separate columns, but from the table with different results. How is this possible as Count should include the Null
values?
SELECT COUNT(Record_Id) FROM my_schema.table
Returns 40493
SELECT COUNT(Status) FROM my_schema.table
Returns 40249
Upvotes: 0
Views: 1099
Reputation: 562
Null Values will not be counted if selecting count of a specific column. Refer here
Upvotes: 1
Reputation: 14628
count()
does not include NULL values. This is specifically for the purpose of counting non-null values, especially in complex queries with lots of outer joins.
If you want to get the number of rows, don't use count on a specific column, but simply use COUNT(1)
, or any other scalar value that will get repeated for every row in the result set.
Upvotes: 1
Reputation: 1270411
This isn't surprising. COUNT()
with an expression as an argument counts the number of non-NULL
values.
Hence, this is saying that Record_Id
is NULL
six more times than status
.
You can get the total number of records using COUNT(*)
.
Upvotes: 1