Junior SQL

What is the difference between COUNT(*) and COUNT(column_name)?

  • COUNT(*): Counts all rows, including rows with NULL values in any column.
  • COUNT(column_name): Counts only non-NULL values in the specified column.

Example:

SELECT COUNT(*) FROM employees; -- Counts all rows

SELECT COUNT(salary) FROM employees; -- Counts rows where salary is

NOT NULL

More from SQL Server Tutorial

All questions for this course