AdBlock Detected!
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.
SQL IFNULL Function |
|
SQL > SQL NULL >
IFNULL Function
The IFNULL( ) function is available in MySQL and SparkSQL, and not in SQL Server, Oracle, or HiveQL (Hive SQL). 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. IFNULL(expr1, expr2) returns the first expression if it is not NULL, otherwise it returns the second. This makes it ideal for substituting default values in place of NULL in MySQL and SparkSQL queries.
For example, if we have the following table, Table Sales_Data
The following SQL,
Result:
This is because NULL has been replaced by 100 via the IFNULL function. The total then becomes 300 + 100 = 400. Frequently Asked QuestionsQ: What does the SQL IFNULL function do? Q: Which databases support IFNULL? Q: How is IFNULL different from COALESCE? Q: What is the equivalent of IFNULL in Oracle and SQL Server?
|
Our website is made possible by displaying ads to our visitors. Please supporting us by whitelisting our website.