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.
If we wanted to use a SQL query to find the number of players on team C, we would write the following:
Once we hit enter and run, our result should be 4 because there are 4 players on team C.