Learn From - Interactive SQL



SQL COUNT() Function


SQL COUNT() function is used to get the count of the numbeer of records in the database table.
Count() can be used to count values in a specific column. It gives the count excluding the NULL values.

SQL COUNT() Syntax


SELECT COUNT(column_name)
FROM table_name

Below is shown the "Authors" table:

FirstName LastName Address City
White Michael 22 Cleveland Av. #24 Berkeley
Hunter Sheryl NULL Salt Lake City
Smith Charlene NULL San Francisco
Jhonson Fernandis 2286 Cram Pl. #81 NULL
Robert Paul 1976 Arlington Pl. NULL

SQL COUNT() Example


Type or Copy the SQL into the Text Editor, click the "View Result" button, to see the result.

To get the total count of records in the Authors table.

Select COUNT(*) as CountOfAuthors from Authors;

Note: It retrieves a count of 5 records.

To get the count of the City column in the Authors table.

Select Count(City) as CountOfCity from Authors;

Note: It retrieves a count of 3 records since there are two NULL values present in the City column.

SQL in Text Editor: