Select*fromEmployee;+----+--------+--------+|ID |Name |Salary|+----+--------+--------+|1 |Gaurav|50000 ||2&nb"/> Select*fromEmployee;+----+--------+--------+|ID |Name |Salary|+----+--------+--------+|1 |Gaurav|50000 ||2&nb">
Home >Database >Mysql Tutorial >What does the MySQL COUNT() function return if there are also some NULL values stored in the column?
When we use the MySQL COUNT() function to count the values stored in a column that also stores some NULL values, MySQL ignores NULLs and returns only non-NULLs value result. To understand it, we use data from table "Employee" as shown below -
mysql> Select * from Employee; +----+--------+--------+ | ID | Name | Salary | +----+--------+--------+ | 1 | Gaurav | 50000 | | 2 | Rahul | 20000 | | 3 | Advik | 25000 | | 4 | Aarav | 65000 | | 5 | Ram | 20000 | | 6 | Mohan | 30000 | | 7 | Aryan | NULL | | 8 | Vinay | NULL | +----+--------+--------+ 8 rows in set (0.00 sec)
Now, the following query applies COUNT() function on "Salary" column -
mysql> Select COUNT(salary) from employee568; +---------------+ | COUNT(salary) | +---------------+ | 6 | +---------------+ 1 row in set (0.15 sec)
From above As can be clearly seen in the result set, MySQL ignores NULL and only returns the count of non-NULL values.
The above is the detailed content of What does the MySQL COUNT() function return if there are also some NULL values stored in the column?. For more information, please follow other related articles on the PHP Chinese website!