Sunday, July 3, 2016

SQL Count() function

SQL Programing language COUNT( ) function use for  count specific table column. It’s a function that counting the number of columns in a criteria. This return by a  select statement.

Count all the column from the table:

SELECT COUNT(*) FROM TableName;

Count distinct values from the specific column:

SELECT COUNT(DISTINCT ColumnName) FROM TableName


In this tutorial we  use this Employee table.

UserId
Salary
Role
1
1200
U
2
1200
U
3
1200
U
4
100
R
5
200
A








Here we count the role of Employee table  .
SELECT  
COUNT(Roleas Roles
from tbl_User where Role='U';


Query Output:-


Roles
3

No comments:

Post a Comment