SQL Select Count

SQL Select Count() function used to count number of records retrieved with some expressions.

Syntax


SELECT COUNT(expression) FROM table_name;



Take Table name Student
ID Name Age City
1 Rahul 20 Pathankot
2 Karan 24 Mohali
3 Ajay 22 Pathankot
4 Ravi 23 Delhi


COUNT With *



SELECT COUNT(*) FROM STUDENT;



Output

COUNT(*) 4


COUNT With column_name



SELECT COUNT(`Name`) FROM STUDENT;



Output

COUNT(`Name`) 4


COUNT With DISTINCT column_name



SELECT COUNT(`City`) FROM STUDENT;



Output

COUNT(`City`) 3

Back To Top