How to Handle NULLs in BigQuery
Last updated July 26, 2026 · By the SaturnSQL team
COALESCE returns the first non-NULL value from a list, IFNULL is a two-argument shortcut for the same thing, and NULLIF turns a matching value into NULL.
SELECT order_id, COALESCE(discount_code, 'NONE') AS discount_code
FROM orders;IFNULL: the two-argument shorthand
SELECT order_id, IFNULL(discount_code, 'NONE') AS discount_code
FROM orders;NULLIF: create NULLs deliberately
NULLIF(a, b) returns NULL when a equals b, otherwise it returns a. It is handy for turning placeholder values like 0 or '' into a real NULL before aggregating.
SELECT order_id, SAFE_DIVIDE(revenue, NULLIF(quantity, 0)) AS unit_price
FROM orders;Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free