Tuesday 24 February 2009

Explain COUNT () function in SQL Server.

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:


Bookmark this Blog in your Favorites

1 Comments:

Blogger Rahul said...

Good Information in COUNT Function.

More on Oracle COUNT Function can be found at

Oracle/SQL COUNT Function

6 June 2013 at 02:06  

Post a Comment

Subscribe to Post Comments [Atom]

<< Home