They server two completely different functions.

ISNULL(value) is a boolean operator that returns 1 or 0 depending on whether or not the value passed in is null. It can be used in if and case statements to determine logic flow. Example:

SELECT OrderID, 
CASE
    WHEN ISNULL(AmountDue) THEN "Paid in full"
    WHEN DATE(DueDate) < date(NOW()) THEN "Order is past due"
    ELSE CONCAT("Order is due on ", CONVERT(VARCHAR, DueDate, 121))
END
FROM OrderDetails;

IFNULL(value1, value2) is used to handle a situation where you want one value, unless it is null, in which case you want a second value. Example:

select IFNULL(MiddleName, "No Middle Name") from customers
Answer from Kevin on Stack Overflow
🌐
W3Schools
w3schools.com › sql › sql_isnull.asp
SQL IFNULL(), ISNULL(), COALESCE(), and NVL() Functions
SQL Examples SQL Editor SQL Quiz SQL Exercises SQL Server SQL Syllabus SQL Study Plan SQL Bootcamp SQL Certificate SQL Training ... Suppose that the "UnitsOnOrder" column is optional, and may contain NULL values. ... In the example above, if any of the "UnitsOnOrder" values are NULL, the result will be NULL. ... The MS Access IsNull() function returns TRUE (-1) if the expression is a null value, otherwise FALSE (0):
🌐
SQLPad
sqlpad.io › tutorial › mastering-sql-a-guide-to-the-ifnull-function
Mastering SQL: A Guide to the IFNULL Function - Dive deep into the SQL IFNULL function with this comprehensive guide. Learn how to use IFNULL to handle NULL values effectively in your database queries. - SQLPad.io
SELECT employee_name, ISNULL(bonus, 0) AS bonus FROM Employees; While both serve to address NULL values, IFNULL is more widely applicable across different SQL databases, making it a versatile tool in your SQL toolkit.
🌐
Reddit
reddit.com › r/sql › difference between isnull and if is null?
r/SQL on Reddit: difference between ISNULL and IF <thing> IS NULL?
November 8, 2013 -

Whenever I need a different value if a column is null, I use the isnull function because, well, that's why it's there, right?

A friend of mine, however, swears by the 'if <column> is null, ..' syntax. As far as I can tell, this is the same thing, it's just a different syntax.

However, different syntax can mean that other things are happening under water, so I became curious as to what the difference was, but was unable to find it on google :/

🌐
Progress
docs.progress.com › bundle › datadirect-openaccess › page › topics › sqlref › ifnull-isnull-nvl.html
IFNULL, ISNULL, NVL
Skip to main contentSkip to search · Powered by Zoomin Software. For more details please contactZoomin
🌐
DataFlair
data-flair.training › blogs › sql-null-functions
SQL Null Functions - ISNULL, IFNULL, Combine, & NULLIF - DataFlair
March 11, 2021 - SELECT emp_id,name, IFNULL(experience, 0) FROM DataFlair; ... Here we can see all the values corresponding to NULL are automatically replaced by 0. ... Example: Let us now check if the experience of each employee in DataFlair is NULL or not NULL. Query: SELECT emp_id,name, ISNULL(experience) FROM DataFlair;
🌐
GeeksforGeeks
geeksforgeeks.org › sql › ifnull-vs-coalesce
IFNULL VS COALESCE - GeeksforGeeks
July 23, 2025 - When dealing with a straightforward scenario involving two arguments and operating within a database system that supports these capabilities, utilize IFNULL/ISNULL. When you need to handle numerous possible NULL values or when you want to construct SQL that is more portable between different database systems, use COALESCE.
🌐
Quora
quora.com › What-is-the-difference-between-NVL-function-IFNULL-function-and-ISNULL-function-in-SQL
What is the difference between NVL function, IFNULL function, and ISNULL function in SQL? - Quora
Answer (1 of 4): NVL function substitute a value when a null value is encountered. NVL2: substitutes a value when a null value is encountered as well as when a non-null value is encountered. The syntax for the NVL2 function is: NVL2( string1, value_if_NOT_null, value_if_null ) string1 is th...
Find elsewhere
🌐
W3Schools
www-db.deis.unibo.it › courses › TW › DOCS › w3schools › sql › sql_isnull.asp.html
SQL ISNULL(), NVL(), IFNULL() and COALESCE() Functions
... In the example above, if any of the "UnitsOnOrder" values are NULL, the result is NULL. Microsoft's ISNULL() function is used to specify how we want to treat NULL values. The NVL(), IFNULL(), and COALESCE() functions can also be used to achieve the same result.
Top answer
1 of 5
136

The main difference between the two is that IFNULL function takes two arguments and returns the first one if it's not NULL or the second if the first one is NULL.

COALESCE function can take two or more parameters and returns the first non-NULL parameter, or NULL if all parameters are null, for example:

SELECT IFNULL('some value', 'some other value');
-> returns 'some value'

SELECT IFNULL(NULL,'some other value');
-> returns 'some other value'

SELECT COALESCE(NULL, 'some other value');
-> returns 'some other value' - equivalent of the IFNULL function

SELECT COALESCE(NULL, 'some value', 'some other value');
-> returns 'some value'

SELECT COALESCE(NULL, NULL, NULL, NULL, 'first non-null value');
-> returns 'first non-null value'

UPDATE: MSSQL does stricter type and parameter checking. Further, it doesn't have IFNULL function but instead ISNULL function, which needs to know the types of the arguments. Therefore:

SELECT ISNULL(NULL, NULL);
-> results in an error

SELECT ISNULL(NULL, CAST(NULL as VARCHAR));
-> returns NULL

Also COALESCE function in MSSQL requires at least one parameter to be non-null, therefore:

SELECT COALESCE(NULL, NULL, NULL, NULL, NULL);
-> results in an error

SELECT COALESCE(NULL, NULL, NULL, NULL, 'first non-null value');
-> returns 'first non-null value'
2 of 5
46

Pros of COALESCE

  • COALESCE is SQL-standard function.

    While IFNULL is MySQL-specific and its equivalent in MSSQL (ISNULL) is MSSQL-specific.

  • COALESCE can work with two or more arguments (in fact, it can work with a single argument, but is pretty useless in this case: COALESCE(a)a).

    While MySQL's IFNULL and MSSQL's ISNULL are limited versions of COALESCE that can work with two arguments only.

Cons of COALESCE

  • Per Transact SQL documentation, COALESCE is just a syntax sugar for CASE and can evaluate its arguments more that once. In more detail: COALESCE(a1, a2, …, aN)CASE WHEN (a1 IS NOT NULL) THEN a1 WHEN (a2 IS NOT NULL) THEN a2 ELSE aN END. This greatly reduces the usefulness of COALESCE in MSSQL.

    On the other hand, ISNULL in MSSQL is a normal function and never evaluates its arguments more than once. COALESCE in MySQL and PostgreSQL neither evaluates its arguments more than once.

  • At this point of time, I don't know how exactly SQL-standards define COALESCE.

    As we see from previous point, actual implementations in RDBMS vary: some (e.g. MSSQL) make COALESCE to evaluate its arguments more than once, some (e.g. MySQL, PostgreSQL) — don't.

    c-treeACE, which claims it's COALESCE implementation is SQL-92 compatible, says: "This function is not allowed in a GROUP BY clause. Arguments to this function cannot be query expressions." I don't know whether these restrictions are really within SQL-standard; most actual implementations of COALESCE (e.g. MySQL, PostgreSQL) don't have such restrictions. IFNULL/ISNULL, as normal functions, don't have such restrictions either.

Resume

Unless you face specific restrictions of COALESCE in specific RDBMS, I'd recommend to always use COALESCE as more standard and more generic.

The exceptions are:

  • Long-calculated expressions or expressions with side effects in MSSQL (as, per documentation, COALESCE(expr1, …) may evaluate expr1 twice).
  • Usage within GROUP BY or with query expressions in c-treeACE.
  • Etc.
🌐
AlphaCodingSkills
alphacodingskills.com › sql › sql-null-functions.php
SQL IFNULL(), ISNULL(), COALESCE() and NVL() Functions - AlphaCodingSkills
SELECT *, Price * (StockQuantity + IFNULL(OrderQuantity, 0)) AS Inventory FROM Product; OR SELECT *, Price * (StockQuantity + COALESCE(OrderQuantity, 0)) AS Inventory FROM Product; ... The SQL Server ISNULL() function can be used to provide an alternative value if column value is NULL:
🌐
Database Guide
database.guide › sql-ifnull-explained
SQL IFNULL() Explained
SQL Server doesn’t have an IFNULL() function, but it does have the ISNULL() function that does the same thing that IFNULL() does in the RDBMSs mentioned above.
🌐
MSSQLTips
mssqltips.com › home › sql server and snowflake null functions – isnull, coalesce, nullif
SQL Server and Snowflake NULL Functions - ISNULL, COALESCE, NULLIF
February 9, 2023 - For SQL Server developers, the ISNULL function is a well-known function for replacing NULL with the specified value: ... The result of the code above will be 0, as the variable is declared but not initialized, so its value is NULL: If we try to apply the ISNULL function in Snowflake, it will not work: ... As we can see, we received an error message clearly mentioning that ISNULL is an unknown function. In Snowflake, instead of the ISNULL, the IFNULL function can be used.
🌐
W3Schools
w3schools.com › mysql › mysql_ifnull.asp
MySQL IFNULL() and COALESCE() Functions
The MySQL IFNULL() function lets you return an alternative value if an expression is NULL. ... If you want to use W3Schools services as an educational institution, team or enterprise, send us an e-mail: [email protected] · If you want to report an error, or if you want to make a suggestion, send us an e-mail: [email protected] · HTML Tutorial CSS Tutorial JavaScript Tutorial How To Tutorial SQL Tutorial Python Tutorial W3.CSS Tutorial Bootstrap Tutorial PHP Tutorial Java Tutorial C++ Tutorial jQuery Tutorial
🌐
MySQLCode
mysqlcode.com › home › mysql isnull() and ifnull() functions
MySQL ISNULL() and IFNULL() Functions - MySQLCode
June 24, 2022 - If the expression is not NULL, IFNULL() returns the expression. ISNULL(expression)Code language: SQL (Structured Query Language) (sql)
🌐
Medium
medium.com › data-engineers-notes › coalesce-vs-ifnull-vs-nullif-in-bigquery-f982bd312274
COALESCE vs IFNULL vs NULLIF in BigQuery - Data Engineer’s Notes - Medium
April 15, 2024 - - IFNULL tests a column for the NULL value, returning the original value if it is NOT NULL and the second value we provide otherwise. The two columns need to be coercible to the same datatype. It’s works like ISNULL in SQL Server.
🌐
Snowflake Documentation
docs.snowflake.com › en › sql-reference › functions › ifnull
IFNULL | Snowflake Documentation
Conditional expression functions · If expr1 is NULL, returns expr2, otherwise returns expr1
🌐
Microsoft Learn
learn.microsoft.com › en-us › sql › t-sql › functions › isnull-transact-sql
ISNULL (Transact-SQL) - SQL Server | Microsoft Learn
Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW) SQL analytics endpoint in Microsoft Fabric Warehouse in Microsoft Fabric SQL database in Microsoft Fabric · Replaces NULL with the specified replacement value. ... The expression to be checked for NULL. check_expression can be of any type. The expression to be returned if check_expression is NULL. replacement_value must be of a type that is implicitly convertible to the type of check_expression. Returns the same type as check_expression. If a literal NULL is provided as check_expression, ISNULL returns the data type of the replacement_value.