Skip to main content

Command Palette

Search for a command to run...

Controlling ordering of NULL values in the ORDER BY clause

Updated
1 min read
Controlling ordering of NULL values in the ORDER BY clause
C

Senior Data Engineer • Contractor / Freelancer • GCP & AWS Certified

Here's something I found out about the ORDER BY clause in BigQuery SQL the other day.

Check out the NULLS FIRST / NULLS LAST clauses. What do they do? They control how to treat NULL values when sorting.

While these are entirely optional, they're actually already happening behind the scenes even if you don't specify them.

🔹 ORDER BY [column] ASC (which is the default) uses NULLS FIRST if unspecified
🔹 ORDER BY [column] DESC uses NULLS LAST if unspecified

Found it useful? Subscribe to my Analytics newsletter at notjustsql.com.


Enjoyed this? Here are some related articles you might find useful:

More from this blog

D

Datawise: A blog on SQL, BigQuery, Analytics, Python Tips and Tricks

204 posts

Data Engineer with a passion for transforming complex data landscapes into insightful stories. Here on my blog, I share insights, challenges, and the ever-evolving dance of technology and business.