SQL COUNT Function
The SQL COUNT function is used to count a number of records of each database table. Here is the syntax:
COUNT([DISTINCT]|[ALL] <expression>)
Let's take a look at employees table
employee_id name salary
----------- -------- -------
1 jack 3000.00
2 mary 2500.00
3 newcomer 2000.00
4 anna 2800.00
5 Tom 2700.00
6 foo 4700.00
This query counts a number of employees of employee table:
SELECT COUNT(*) as total_employee FROM employees
Here is the output:
total_employee
--------------
6