SQL COUNT Function
Syntax
The COUNT function in SQL is used to return the number of rows or non-NULL values in a column.
-- Count all rows in a tableSELECT COUNT(*)FROM table_name;
-- Count non-NULL values in a specific columnSELECT COUNT(column1)FROM table_name;
-- Count distinct values in a columnSELECT COUNT(DISTINCT column1)FROM table_name;Example
-- Count all rows in the employees tableSELECT COUNT(*)FROM employees;/* Output:| COUNT(*) ||----------|| 3 |*/
-- Count non-NULL values in the age columnSELECT COUNT(age)FROM employees;/* Output:| COUNT(age) ||------------|| 2 |*/
-- Count distinct departmentsSELECT COUNT(DISTINCT department)FROM employees;/* Output:| COUNT(DISTINCT department) ||----------------------------|| 3 |*/