Did you find this useful?
Socialize it today.


SQL COUNT Function

Saturday, December 10, 2011

tags SQL

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

employeeIDemployeeNameage
1000John Smith40
1001Fred White27
1002Jane Scott53
1003Samuel Williams31


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

Total Count
4


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.

Please help us spread the word by socializing it today!

email contact us

Did you find something wrong with the information on this page? Please take a moment to report it to us so that we can continue to improve the quality of the information on this site. Click here to report an issue with this page.



Recommended Books & Training Resources

Head First SQL: Your Brain on SQL A Learners Guide SQL Cookbook