SQL Nulls Finally Made Sense: COALESCE, NULLIF, and Safer Calculations
dev.to·1d·
Discuss: DEV
🗄️Database Design
Preview
Report Post

This was one of those learning days where SQL didn’t look hard… but kept quietly breaking my queries.

Not with errors.

With NULLs.

Today I focused on understanding:

  • COALESCE
  • NULLIF
  • basic arithmetic operations
  • and how functions like SUM, ROUND, and MOD behave when NULL is involved

These are things I’ve seen mentioned casually in tutorials, but I didn’t really feel why they mattered until I started doing real calculations.

The Problem I Kept Running Into

I’d write what looked like a simple query:

  • calculate totals
  • divide one column by another
  • show numeric results

And suddenly…

  • values disappeared
  • calculations returned NULL
  • or worse everything broke because of a divide-by-zero

That’s when I realised:

SQL is extremely strict about missi…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help