SQL COUNT(*) Function

Definition and Usage

The COUNT(*) function returns the number of rows selected from the given selection.

Syntax

SELECT COUNT(*) FROM table

Example

Name Age
Adams, John 38
Bush, George 33
Carter, Thomas 18

Example 1

This example returns the number of rows in the 'Persons' table:

SELECT COUNT(*) FROM Persons

Result:

3

Example 2

Return the number of people over 20 years old:

SELECT COUNT(*) FROM Persons WHERE Age>20

Result:

2