COUNT() aggregate function returns the total number of rows that match the specified criteria.
SELECT COUNT(column_name)FROM table_name;
COUNT() is a function that takes the name of a column as an argument and counts the number of rows where the column is not
Note: A column name of the table can also be used instead of
COUNT(*), this variation
COUNT(column_name) will not count
NULL values in that column.
Suppose there’s an
employees table with the following values:
To find the total number of employees who have less than 5 years of experience, the given query can be used:
SELECT COUNT(*)FROM employeesWHERE experience < 5;
The result would be:
- Anonymous contributors
Learn SQL on Codecademy
- Anonymous contributorsAnonymous contributors