What is the use of IFNULL() operator in MySQL?

We use IFNULL operator in MySQL to get a non-null value for a column with null value.

IFNULL(expr1, expr2)
If expr1 is not null then expr1 is returned. If expr1 is null then expr2 is returned.

Eg. SELECT name, IFNULL(id,’Unknown’) AS ‘id’ FROM user;

If id is not null then id is returned. If id is null then Unknown is returned.

Read the full book at www.amazon.com
Posted in MySQL, MySQL Interview Questions

Leave a Reply

Your email address will not be published. Required fields are marked *