Use COALESCE:

CopySELECT COALESCE(field_a, field_b)

COALESCE is an ANSI standard function that returns the first non-null value from the list of columns specified, processing the columns from left to right. So in the example, if field_a is null, field_b value will be displayed. However, this function will return NULL if there is no non-null value from the columns specified.

It's supported on MySQL (I've used it on 4.1), SQL Server (since v2000), Oracle 9i+...

Answer from OMG Ponies on Stack Overflow
🌐
W3Schools
w3schools.com › sql › sql_isnull.asp
W3Schools.com
The COALESCE() function works in MySQL, SQL Server, and Oracle (not in MS Access). ... The MySQL IFNULL() function replaces NULL with a specified value.
🌐
W3Schools
w3schools.com › sql › func_mysql_ifnull.asp
MySQL IFNULL() Function
SQL Examples SQL Editor SQL Quiz SQL Exercises SQL Server SQL Syllabus SQL Study Plan SQL Bootcamp SQL Training ... The IFNULL() function returns a specified value if the expression is NULL.
🌐
Snowflake Documentation
docs.snowflake.com › en › sql-reference › functions › ifnull
IFNULL | Snowflake Documentation
Snowflake performs implicit conversion of arguments to make them compatible. For example, if one of the input expressions is a numeric type, the return type is also a numeric type. That is, SELECT IFNULL('17', 1); first converts the VARCHAR value '17' to the NUMBER value 17, and then returns the first non-NULL value.
🌐
Medium
medium.com › @alexandra.petra.berger › handling-nulls-in-sql-isnull-ifnull-coalesce-a480c3584c32
Handling NULLs in SQL: ISNULL(), IFNULL(), COALESCE() | by Alexandra Petra Berger | Medium
November 30, 2024 - Applicable in SQL Server, MySQL, Hive. ... Replaces a NULL value with a specified value and returns the substituted value. Commonly used to handle NULL values in result sets. Applicable in MySQL and Hive.
🌐
DataCamp
datacamp.com › doc › mysql › mysql-ifnull
MySQL IFNULL Keyword: Usage & Examples
Here, `IFNULL` ensures that a missing `last_name` is replaced with 'Unknown', allowing for complete name concatenation. sql SELECT product_name, price, quantity, IFNULL(price * quantity, 0) AS total_value FROM products;
Find elsewhere
🌐
Study.com
study.com › computer science courses › introduction to sql
SQL: IFNULL Function | Study.com
The IFNULL function takes two arguments. It checks to see if the first argument is not NULL. If it is not NULL, it returns the first argument. Otherwise, it returns the second argument.
🌐
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.
🌐
DataFlair
data-flair.training › blogs › sql-null-functions
SQL Null Functions - ISNULL, IFNULL, Combine, & NULLIF - DataFlair
March 11, 2021 - Using this recognizing capacity, one can further perform operations on the null values like the aggregate functions in SQL. Some of the functions are as follows: Let us now have a look at our demo database – ‘DataFlair’ Query: ... Example: Let us view the experience of each employee in DataFlair and replace the NULL value with 0 years of experience. Query: SELECT emp_id,name, IFNULL(experience, 0) FROM DataFlair;
🌐
IONOS
ionos.com › digital guide › server › configuration › sql ifnull
How to use the SQL IFNULL() function to output alternative values
February 7, 2025 - The SQL IFNULL() function is used to check the value of an ex­pres­sion. If this is NULL, an al­ter­na­tive value is output instead.
🌐
IBM
ibm.com › docs › en › db2-for-zos › 12.0.0
IFNULL scalar function - Db2 SQL
January 20, 2026 - IFNULL is identical to the COALESCE scalar function except that IFNULL is limited to two arguments instead of multiple arguments.
🌐
DB Vis
dbvis.com › thetable › mysql-ifnull-everything-you-need-to-know
MySQL IFNULL - Everything You Need to Know
June 20, 2024 - MySQL and other database management systems have many functions. Each of those functions solve a concrete problem NULLIF, or IFNULL, is used to figure out whether two values are equal.
🌐
Spring
docs.spring.io › spring-boot › appendix › application-properties › index.html
Common Application Properties :: Spring Boot
Various properties can be specified inside your application.properties file, inside your application.yaml file, or as command line switches. This appendix provides a list of common Spring Boot properties and references to the underlying classes that consume them · management.appoptics.met...
🌐
W3Schools
w3schools.com › sql › sql_default.asp
SQL DEFAULT Constraint
String Functions: ASCII CHAR_LENGTH ... BINARY CASE CAST COALESCE CONNECTION_ID CONV CONVERT CURRENT_USER DATABASE IF IFNULL ISNULL LAST_INSERT_ID NULLIF SESSION_USER SYSTEM_USER USER VERSION SQL Server Functions...
🌐
W3Schools
w3schools.com › mysql › mysql_ref_functions.asp
MySQL Functions
String Functions ASCII CHAR_LENGTH CHARACTER_LENGTH CONCAT CONCAT_WS FIELD FIND_IN_SET FORMAT INSERT INSTR LCASE LEFT LENGTH LOCATE LOWER LPAD LTRIM MID POSITION REPEAT REPLACE REVERSE RIGHT RPAD RTRIM SPACE STRCMP SUBSTR SUBSTRING SUBSTRING_INDEX TRIM UCASE UPPER Numeric Functions ABS ACOS ASIN ATAN ATAN2 AVG CEIL CEILING COS COT COUNT DEGREES DIV EXP FLOOR GREATEST LEAST LN LOG LOG10 LOG2 MAX MIN MOD PI POW POWER RADIANS RAND ROUND SIGN SIN SQRT SUM TAN TRUNCATE Date Functions ADDDATE ADDTIME CURDATE CURRENT_DATE CURRENT_TIME CURRENT_TIMESTAMP CURTIME DATE DATEDIFF DATE_ADD DATE_FORMAT DATE_