Differentiate between count() and count(*) functions in SQL with appropriate example.

 

Answer:

COUNT( )

COUNT(*)

Always used with a column name passed as argument and returns the count of the number of rows with non-null values in the column given as argument.

Returns the count of all rows in the table.

 

Example:

Question 25 Example 1 -Teachoo.png

COUNT DEPT NAME return 4 -Teachoo.png

COUNT DEPT NAME return 5 -Teachoo.png

  • COUNT(*) returns 5 since there are 5 records in the table DEPARTMENT.
  • COUNT(DEPT_NAME) return 4 since there is 1 null value in the column DEPT_NAME.
Remove Ads
Davneet Singh's photo - Co-founder, Teachoo

Made by

Davneet Singh

Davneet Singh is an IIT Kanpur graduate and has been teaching for 16+ years. At Teachoo, he breaks down Maths, Science and Computer Science into simple steps so students understand concepts deeply and score with confidence.

Many students prefer Teachoo Black for a smooth, ad-free learning experience.