SQL COALESCE vs ISNULL: Key Differences
By Sharon Ben-Moshe · August 26, 2026 · 2 min read
Sharon Ben-Moshe is the founder of sqlfmt, a browser-based SQL formatter and validator with misspelled-keyword suggestions across PostgreSQL, MySQL, SQLite, SQL Server, and BigQuery.
Compare SQL COALESCE and ISNULL: argument count, portability, return types, nullability, evaluation behavior, and the MySQL naming trap.
Quick answer
Use COALESCE when SQL must work across databases or when more than two fallback values are needed. In SQL Server, ISNULL takes two arguments and follows different type and nullability rules; in MySQL, ISNULL(expr) is a null test rather than a replacement function.
FAQs
Is COALESCE standard SQL?
COALESCE is a SQL-standard conditional expression and is broadly available across major SQL databases. It returns the first non-NULL argument, making it the safer default when a query needs to remain portable.
Is SQL Server ISNULL the same as COALESCE?
No. SQL Server ISNULL accepts two arguments and uses the first argument’s data type. COALESCE accepts a variable number of arguments and uses CASE-expression type-precedence rules; the expressions can also have different nullability metadata.
Can I use ISNULL to replace NULL in MySQL?
Not with SQL Server’s meaning. In MySQL, ISNULL(expr) tests whether expr is NULL. Use COALESCE(expr, fallback) or IFNULL(expr, fallback) to return a replacement value.
Should I use COALESCE or IS NULL?
Use COALESCE to return a fallback value. Use IS NULL in a predicate when filtering or branching on missing data. They solve different problems, and equality written as = NULL does not test for nulls correctly.
Keep reading
SQL ROW_NUMBER(): How to Number Rows
By Sharon Ben-Moshe · Aug 26, 2026
Learn SQL ROW_NUMBER with practical examples for numbering rows, latest-row-per-group queries, tie-breaking, and when RANK is the better choice.
Read postSQL Date Difference: DATEDIFF by Database
By Sharon Ben-Moshe · Aug 26, 2026
Calculate date differences in SQL Server, MySQL, PostgreSQL, SQLite, and BigQuery. Learn syntax, argument order, timestamp behavior, and boundary rules.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.