sql tutorial

SQL IFNULL Function


  SQL > SQL Commands > IFNULL Function

The IFNULL() function is available 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.

For example, if we have the following table,

Table Sales_Data
store_name Sales
Store A 300
Store B NULL

The following SQL,

SELECT SUM(IFNULL(Sales,100)) FROM Sales_Data;

returns 400. This is because NULL has been replaced by 100 via the ISNULL function.

SQL NVL Function >>

Link to this page: If you find this page useful, we encourage you to link to this page. Simply copy and paste the code below to your website, blog, or profile.



Copyright 1999-2009 1keydata.com.   All Rights Reserved.     Privacy Policy  








SQL UNION
SQL UNION ALL
SQL INTERSECT
SQL MINUS
SQL LIMIT
SQL TOP
SQL Subquery
SQL EXISTS
SQL CASE
SQL NULL
SQL ISNULL
SQL IFNULL
SQL NVL
SQL COALESCE
SQL NULLIF
SQL Rank
SQL Median
SQL Running Totals
SQL Percent to Total
SQL Cumulative Percent to Total

SQL Jobs


CSS Tutorial

PHP Tutorial



Site Map
Resources



Data Warehousing & Business Intelligence