Using COUNT (Column_Name) function
The COUNT (Column_Name) function is used to view the number of specified rows without displaying the null values.
Ex :
Select count(EmployeeName) as EmployeeNameRamesh from Employees
Where EmployeeName
This Query will display the total numbers who has name “Ramesh”. For ex. if there were eight people in the name of “Ramesh” in the table, then the output will show as “8”.
Using COUNT (*) function
The COUNT (*) function is used to view the total number of rows in a particular table.
Ex :
Select count(*) as NumberofEmployees from Employees
This Query will display the total number of rows in the table “Employees”, the output will be displayed in the column name of “NumberofEmployees”.
Using COUNT (DISTINCT Column_Name) function
The COUNT (DISTINCT Column_Name) function is used to view the distinct number of records.
Ex :
Select count(distinct Employees) as NumberofEmployees from Employees
This Query will display the total number of employees distinctly with the new table name “NumberofEmployees”. i.e employees records with the same name is not shown repeatedly.
Labels: COUNT () function in SQL Server