Site icon Database Tutorials

COUNT Function in SQL Server(TSQL)

 

We find the number of records in a data set with the Count function. For example, we can find the number of records in a table or the number of records in a data set grouped with GROUP BY.

Let’s make examples for a better understanding of COUNT Function.

Example:

First, we create a table with the help of the following script and add a few records into this table.

Let’s calculate the number of records in the table with one of the following queries: (Both queries return the same result. If you type a column name instead of 1 or *, null records are not calculated.)

or

Calculate how many products each person has by grouping table by [Name] column:

Exit mobile version