SQL SELECT COUNT : The SQL COUNT() function is used to return the number of rows in a query.
The COUNT() function is used with SQL SELECT statement and it is very useful to count the number of rows in a table having enormous data.
For example: If you have a record of the voters in selected area and want to count the number of voters then it is very difficult to do it manually but you can do it easily by using the SELECT COUNT query.
Let\’s see the syntax of SQL COUNT statement.
SELECT COUNT (expression)
FROM tables
WHERE conditions;
Let\’s see the examples of sql select count function.
SELECT COUNT(column_name)
SELECT COUNT(name) FROM employee_table;
It will return the total number of names of employee_table. But null fields will not be counted.
SELECT COUNT(*)
SELECT COUNT(*) FROM employee_table;
The \”select count(*) from table\” is used to return the number of records in table.
SELECT COUNT (DISTINCT column_name)
SELECT COUNT(DISTINCT name) FROM employee_table;
It will return the total distinct names of employee_table.