Custom Search

Saturday, August 23, 2008

SQL COUNT(*) Function

The COUNT(*) function returns the number of selected rows in a selection.
Syntax

SELECT COUNT(*) FROM table

Example

With this "Persons" Table:
Name Age
Hansen, Ola 34
Svendson, Tove 45
Pettersen, Kari 19

This example returns the number of rows in the table:

SELECT COUNT(*) FROM Persons

Result:

3

Example

Return the number of persons that are older than 20 years:

SELECT COUNT(*) FROM Persons WHERE Age>20

Result:

2

No comments: