

There are 7 records in employee table among which one record contain NULL values for Emp_Salary. mysql> SELECT COUNT(Emp_Salary) FROM employee We will display the number of records which exists for Emp_Salary. So, that particular record is ignored and 6 is displayed as an output. There are 7 records in employee table among which, one record contain NULL values for Emp_Name. mysql> SELECT COUNT(Emp_Name) FROM employee We will display the number of records which exists for Emp_Name. There are 7 records which contain unique Emp_ID. mysql> SELECT COUNT(Emp_ID) FROM employee We will display the number of records which exists for Emp_ID. Syntax: SELECT COUNT(ColumnName) FROM tablename While using COUNT() function with columnname as a parameter, the records which contain NULL values for that record will be ignored. It simply means -14 will be assigned to each and every row present in a table and then that rows will be summed up to give a total and displayed as an output.ĬOUNT(ColumnName) is used to find the number of records which contain values for the specified column. So, 7 is displayed as an output even though we have passed -14 as a parameter to COUNT() function. Let us see what happens when we pass -14 as a parameter to COUNT() function. It simply means 14 will be assigned to each and every row present in a table and then that rows will be summed up to give a total and displayed as an output. Passing an integer to a COUNT() function does not mean to count those number of rows in table.

So, 7 is displayed as an output even though we have passed 14 as a parameter to COUNT() function. Let us see what happens when we pass 14 as a parameter to COUNT() function. Even the results of COUNT (1) and COUNT (*) are also same.Įxample 1: We will display the number of records present in employee table using COUNT (1). COUNT (1) function works same as COUNT (*). The results of COUNT (1) function will contain NULL as well as duplicate entries also into consideration. There are 7 records present in employee table.ĬOUNT (1) is also used to display the number of records present in a table. mysql> USE employeedb ħ rows in set (0.00 sec) mysql> SELECT COUNT(*) FROM employee We will find the number of records present in ‘employee’ table using COUNT () function. We will consider this table and database for all the subsequent examples. Then in that database we will create a table “employee” and insert records into the table. The results of COUNT (*) function will contain NULL as well as duplicate entries also into consideration.įirst we will create a database with name “employeedb”.

This function counts the number of records in a table if the condition is not specified.COUNT( ) is an aggregate function in SQL.
