dcsimg
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Tip: Understanding NULL in MySQL

See how to work with NULL in MySQL and examine a few examples in which you might be confused with the output unless you are very comfortable using NULL.


advertisement

WEBINAR:

On-Demand

Building the Right Environment to Support AI, Machine Learning and Deep Learning


NULL is a unique value. It represents a value that is not defined and that is not really equal to BLANK ('').

While using it in queries, we need to use the utmost care.

Here are a few examples in which you might be confused with the output unless you are very comfortable using NULL.



1. When NULL is added to a number, the output is still NULL

Query: SELECT 1 + NULL;

Output:

+-----------+
| 1 + NULL  |
+-----------+
| (NULL)    |
+-----------+

2. When used with a string function such as CONCAT

Query: SELECT CONCAT('Indigo',NULL);

Output:

+------------------------+
| CONCAT('Indigo',NULL)  |
+------------------------+
| (NULL)                 |
+------------------------+

Alternatively, when the query is SELECT CONCAT('Indigo',' Nation');

Output:

+-----------------------------+
| CONCAT('Indigo',' Nation')  |
+-----------------------------+
| Indigo Nation               |
+-----------------------------+


   
Sridhar M S. is a Java developer from Bangalore, India. He holds a master's degree in Computer Science.
Thanks for your registration, follow us on our social networks to keep up-to-date