What MySQL returns if we pass column name, containing a NULL value, as one of the arguments of CONCAT() function?

MySQLMySQLi Database

As we know that CONCAT() function will return NULL if any of the argument of it is NULL. It means MySQL will return NULL if we pass column name, containing a NULL value, as one of the arguments of CONCAT() function. Following is an example of ‘Student’ table to explain it.

Example

In this example, we are concatenating the values of two strings and at 5th row one, the value is NULL hence the concatenation result is also NULL.

mysql> Select Name, Address, CONCAT(Name,' Resident of ',Address)AS 'Detail of Student' from Student;

+---------+---------+---------------------------+
| Name    | Address | Detail of Student         |
+---------+---------+---------------------------+
| Gaurav  | Delhi   | Gaurav Resident of Delhi  |
| Aarav   | Mumbai  | Aarav Resident of Mumbai  |
| Harshit | Delhi   | Harshit Resident of Delhi |
| Gaurav  | Jaipur  | Gaurav Resident of Jaipur |
| Yashraj | NULL    | NULL                      |
+---------+---------+---------------------------+

5 rows in set (0.00 sec)
raja
Published on 19-Feb-2018 18:52:59
Advertisements