The SQL COUNT function returns the number of values of the specified column.
Null values are not counted. This function can also be used to count the number of rows in the table.
Employees Table
employeeID | employeeName | age |
1000 | John Smith | 40 |
1001 | Fred White | 27 |
1002 | Jane Scott | 53 |
1003 | Samuel Williams | 31 |
In this example, we want to count the number of rows in a table.
Syntax
SELECT COUNT(column_name)
FROM Table
Or
SELECT COUNT(*)
FROM Table
|
Example
SELECT COUNT(employeeID) as [Total Count]
FROM employees
Or
SELECT COUNT(*) as [Total Count]
FROM employees
|
Results
The SQL COUNT function is used to count the number of rows in a table. You can also use other key words such as
DISTINCT and WHERE to further filter the data and make the results more specific to the range of data you are looking for.
Did you find the page informational and useful? Share it using one of your favorite social sites.
Recommended Books & Training Resources