IFNULL in SQL - sql - sql tutorial - learn sql




  • MySQL IFNULL function is one of the MySQL control flow functions that accepts two arguments and returns the first argument if it is not NULL. Otherwise, the IFNULL function returns the second argument.
  • The IFNULL( ) function is available only in MySQL, and not in SQL Server or Oracle.
  • This function takes two arguments. If the first argument is not NULL, the function returns the first argument.
  • Otherwise, the second argument is returned. This function is commonly used to replace NULL value with another value.
  • It is similar to the NVL function in Oracle and the ISNULL Function in SQL Server.
Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

Syntax:

                                  IFNULL(expression1, expression2);

Example 1: MySQL IFNULL() function

  • The following MySQL statement returns the first expression, i.e. 0, since the first expression is not NULL.
1.	SELECT IFNULL(0,2);  

Output :

mysql> SELECT IFNULL(0,2);
+-------------+
| IFNULL(0,2) |
+-------------+
|           0 | 
+-------------+

1 row in set (0.03 sec)

Example 2: IFNULL() function with non zero 1st argument

  • The following MySQL statement returns the first expression, i.e. 1, since the first expression is not NULL.
	SELECT IFNULL(1,2);  

Output :

mysql> SELECT IFNULL(1,2);
+-------------+
| IFNULL(1,2) |
+-------------+
|           1 | 
+-------------+
1 row in set (0.00 sec)

Tags : sql tutorial , pl sql tutorial , mysql tutorial , oracle tutorial , learn sql , sql server tutorial

Example 3: IFNULL() function NULL

  • The following MySQL statement returns the second expression, i.e. 2, since the first expression is NULL.
	SELECT IFNULL(NULL,2);  

Output :

mysql> SELECT IFNULL(NULL,2);
+----------------+
| IFNULL(NULL,2) |
+----------------+
|              2 | 
+----------------+
1 row in set (0.00 sec)

This tutorial provides more the basic needs and informations on sql tutorial , pl sql tutorial , mysql tutorial , sql server , sqlcode , sql queries , sql , sql formatter , sql join , w3schools sql , oracle tutorial , mysql , pl sql , learn sql , sql tutorial for beginners , sql server tutorial , sql query tutorial , oracle sql tutorial , t sql tutorial , ms sql tutorial , database tutorial , sql tutorial point , oracle pl sql tutorial , oracle database tutorial , oracle tutorial for beginners , ms sql server tutorial , sql tutorial pdf

Related Searches to IFNULL in SQL

s

Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add wikitechy.com to your ad blocking whitelist or disable your adblocking software.

×