- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How MySQL SUM() function evaluates if the column having NULL values too?
Suppose if we are calculating the sum of the values of a column which also have NULL values then MySQL SUM() function ignores the NULL values and does the sum of the rest of the values. To understand it, consider the following example of table ‘employee’, having following details −
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, suppose if we want to have the total salary of the employees from above table then while calculating it with SUM() function, it ignores the NULL values. The following query will produce the required result set −
mysql> Select SUM(Salary) from Employee; +-------------+ | SUM(Salary) | +-------------+ | 210000 | +-------------+ 1 row in set (0.00 sec)
It can also be verified with the help of the following query −
mysql> Select SUM(Salary) from Employee WHERE Salary IS NOT NULL; +-------------+ | SUM(Salary) | +-------------+ | 210000 | +-------------+ 1 row in set (0.00 sec)
- Related Articles
- How MySQL SUM() function evaluates if it got the column, having character data type, as its argument?
- How MySQL stored function evaluates if it got NULL value while using the dynamic values from a table?
- How MySQL evaluates if I will use an expression within SUM() function?
- What would be the output of MySQL SUM() function if a column having no values has been passed as its argument?
- How MySQL evaluates if I store date along with time value in a column having DATE data type?
- How MySQL evaluates if we use EXISTS operator with the subquery that returns NULL?
- What MySQL returns when we use DISTINCT clause with the column having multiple NULL values?
- How MySQL evaluates when I use a conditional expression within SUM() function?
- What MySQL COUNT() function returns if there are some NULL values stored in a column also?
- How MySQL SUM() function evaluates if it is used with SELECT statement that returns no matching rows?
- How can we use MySQL SUM() function to calculate the sum of only dissimilar values of the column?
- MySQL update column to NULL for blank values
- How can we use MySQL SUM() function with HAVING clause?
- Check for NULL or NOT NULL values in a column in MySQL
- How to check whether column value is NULL or having DEFAULT value in MySQL?

Advertisements