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
The Comprehensive Guide to SQL Data Types: Storage, Precision, and Cross-Dialect Portability
By Sharon Ben-Moshe · Oct 13, 2026
The complete guide to SQL data types across PostgreSQL, MySQL, SQL Server, and SQLite. Numeric precision, character sets, timestamps, and JSON.
Read postThe Definitive Guide to SQL Window Functions: Syntax, Framing, and Real-World Recipes
By Sharon Ben-Moshe · Oct 13, 2026
The comprehensive guide to SQL window functions. Master OVER, PARTITION BY, ORDER BY, window frames (ROWS vs RANGE), and ranking recipes.
Read postTry it now
Paste your SQL into sqlfmt — format, validate, and catch typos free in your browser.