Last answered:

21 May 2020

Posted on:

20 May 2020

0

Resolved: I am confused using Count(*)

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 answers ( 0 marked as helpful)
Instructor
Posted on:

21 May 2020

0
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

Submit an answer