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:
- 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.