-- Created on savesnippets.com · https://savesnippets.com/bONV9DDfTpotta -- Show display_name, fall back to email, fall back to "Anonymous" SELECT id, COALESCE(display_name, email, 'Anonymous') AS shown_name FROM users; -- NULLIF — divide by zero protection SELECT amount, qty, amount / NULLIF(qty, 0) AS unit_price -- returns NULL instead of error FROM line_items; -- Treat empty string as NULL (common normalization) UPDATE users SET email = NULLIF(TRIM(email), ''); -- Difference between COALESCE and ISNULL/IFNULL: -- COALESCE — standard SQL, variadic, returns the type of the first non-null -- IFNULL — MySQL, takes exactly 2 args -- ISNULL — SQL Server, takes exactly 2 args