Skip to main content
/1 min read

SQL COUNT Tutorial

How COUNT Works

Returns Number of Rows

COUNT counts entries that meet the WHERE condition.

Syntax

SELECT COUNT(column_1) FROM table WHERE condition;

Common Use Case

Counting players on a team — SELECT COUNT(*) FROM players WHERE team = 'C';

Tip: COUNT(*) vs COUNT(column)

COUNT(*) counts all rows; COUNT(column) skips NULLs in that column.

Master SQL at Noble Desktop

Noble Desktop's SQL Bootcamp covers queries, joins, aggregations, and the full SQL toolkit data analysts use every day.

In this tutorial, we'll go through the basics of the COUNT function in SQL, the syntax of it, and walk through an example of the COUNT function.

COUNT Function

  • The COUNT function returns the number of rows in the data based on the given criteria.

  • It returns the count of entries or rows that meet the condition.

  • Syntax: SELECT COUNT(column_1) FROM table WHERE condition ;

Example

Let’s say we have a basketball league and we keep records of each player, which team they are on, and their basic statistics.

Stats Table

If we wanted to use a SQL query to find the number of players on team C, we would write the following:

SQL COUNT Function

Once we hit ENTER and run, our result should be 4 because there are 4 players on team C.