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

queries can help us work with null values in queries and behave as we need.  is a suitable function and can be used where you want to treat null values methodically.

For example:

CREATE TABLE 'EMPLOYEE' (
'ID' INT PRIMARY KEY AUTO_INCREMENT,
'FirstName' VARCHAR(25) NULL,
'LastName' VARCHAR() NULL
)
COLLATE='utf8_bin'
ENGINE=InnoDB
;

In this table, we can see that the columns FirstName and LastName can have null values. Assuming that the is inserted as below:

INSERT INTO 'EMPLOYEE' ('FirstName', 'LastName') VALUES ('John', 'Dee');
INSERT INTO 'EMPLOYEE' ('FirstName', 'LastName') VALUES ('Joshu', NULL);
INSERT INTO 'EMPLOYEE' ('FirstName', 'LastName') VALUES (NULL, 'Kyle'); 

And execute the following query

SELECT IFNULL(FIRSTNAME,"UnDefined") AS FIRSTNAME FROM EMPLOYEE
+ -- -- -- -- -- -- -+
| FIRSTNAME |
+ -- -- -- -- -- -- -+
| John |
| Joshu |
| UnDefined |
+ -- -- -- -- -- -- -+

You can see that the values where FIRSTNAME is NULL is returned as UnDefined and in other cases the value in the FIRSTNAME is returned. With this output, the values can be used in an application as needed.

 

Visit the DevX Tip Bank

 



Source link
thanks you RSS link
( http://www.devx.com/DevX/--ifnull-in-mysql.html)

LEAVE A REPLY

Please enter your comment!
Please enter your name here