The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

I am confused using Count(*)

I am confused using Count(*)

Super Learner
0
Votes
1
Answer

I understand that * is a wildcard and what that is.
When using it in the SELECT statements, I understand that it considers all fields, so I dont need to specify them individually.
However, I am confused when I use it in the COUNT() statement. It seems that it should be returning all values in the table, not just the records.
What is the gap in my understanding with the solution to the exercises on the related lesson?
Thanks for any insight.

QUERY:

SELECT COUNT(*) FROM salaries WHERE salary > 100000;

1 Answer

365 Team
0
Votes

Hi Mike!
Thanks for reaching out.
In theory, there’s not much of a gap. COUNT(*) returns the number of all rows of the given field from the data set, including NULL values. If you are using a specific field as an argument (i.e. e.g. COUNT(emp_no)), the NULL values will be ignored and only the number of the non-null values will be retrieved.  
Hope this helps.
Best,
Martin

I think so. If I understand your explanation, the wildcard in the Count() function does not represent fields, but records including null values. Is that right?

2 weeks

Hi Mike! Thank you very much for your reply. The wildcard in the COUNT() function does not represent fields, indeed. It means “all fields” and returns *all* records – such that contain NULL and NON NULL values. Hope this helps. Best, Martin

3 days