
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
What would be the output of MySQL SUM() function if a column having no values has been passed as its argument?
When MySQL SUM() function got a column, having no values, as an argument then it will return NULL, rather than 0, as output. The column can be of any data type. Following the example, using a table named ‘social’ having only one column named ‘id’ with no values, will illustrate it
Example
mysql> Describe Social; +-------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+-------------+------+-----+---------+-------+ | Id | int(11) | YES | | NULL | | | Name | varchar(20) | YES | | NULL | | +-------+-------------+------+-----+---------+-------+ 2 rows in set (0.00 sec) mysql> Select * from Social; Empty set (0.00 sec) mysql> Select SUM(id) from Social; +---------+ | SUM(id) | +---------+ | NULL | +---------+ 1 row in set (0.00 sec) mysql> Select SUM(Name) from Social; +-----------+ | SUM(Name) | +-----------+ | NULL | +-----------+ 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?
- What would be the output of MySQL ELT() function if the index number, provided as an argument, is not an integer?
- How MySQL SUM() function evaluates if the column having NULL values too?
- What is MySQL STRCMP() function and what would be the output of this function?
- What would be output if we will try to extract time values by providing the date values only to MySQL EXTRACT() function?
- What MySQL returns if we use UNIX_TIMESTAMP() function with no argument?
- What MySQL COALESCE() function returns if it has a blank, but not NULL, as the first argument?
- What would be effect of negative value of second argument, which specifies the number of decimal places, on the output of MySQL ROUND() function?
- What would be effect of negative value of second argument, which specifies the number of decimal places, on the output of MySQL TRUNCATE() function?
- What would be the effect on MySQL output if we have the combination of NULL and other values in the list of strings, provided as arguments in FIELD() function?
- When MySQL SUBSTRING_INDEX() function returns the same string, provided in the argument, as output?
- How can MySQL COALESCE() function be used with MySQL SUM() function to customize the output?
- What would be the result if we perform any kind of arithmetic calculations in MySQL having one of the arguments as NULL?
- What happens if we provide NULL as an argument to MySQL CHAR() function?
- What MySQL returns if the list of strings, provided as argument in FIELD() function, are NULL?

Advertisements